♻️ Refactor config
Make it easier to setup stores
This commit is contained in:
parent
ecae0d5f83
commit
6f06adc37d
12 changed files with 623 additions and 81 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue