♻️ Refactor config

Make it easier to setup stores
This commit is contained in:
Dan Jones 2025-01-26 20:07:45 -06:00
commit 6f06adc37d
12 changed files with 623 additions and 81 deletions

View file

@ -9,7 +9,7 @@ import (
var ErrNoFactory = errors.New("unknown factory")
type StoreFactory func(config.Config) (Store, error)
type StoreFactory func(config.Store) (Store, error)
var factories map[string]StoreFactory
@ -26,13 +26,18 @@ func GetFactory(name string) StoreFactory {
}
func MakeStore(name string, conf config.Config) (Store, error) {
st, err := conf.Store(name)
if err != nil {
return nil, err
}
if name == "" {
name = conf.Conn.Store
name = st.Name()
}
f, ok := factories[name]
if !ok {
return nil, fmt.Errorf("%w: %s", ErrNoFactory, name)
}
return f(conf)
return f(st)
}