✨ Improve Store
Still need to fill out SQLite bootstrap Also setup plug-in system mechanism
This commit is contained in:
parent
c4513aa94b
commit
e7b88bcc09
10 changed files with 154 additions and 6 deletions
34
store/factory.go
Normal file
34
store/factory.go
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
package store
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"codeberg.org/danjones000/lenore/config"
|
||||
)
|
||||
|
||||
var ErrNoFactory = errors.New("unknown factory")
|
||||
|
||||
type StoreFactory func(config.Config) (Store, error)
|
||||
|
||||
var factories map[string]StoreFactory
|
||||
|
||||
func init() {
|
||||
factories = make(map[string]StoreFactory)
|
||||
}
|
||||
|
||||
func AddFactory(name string, f StoreFactory) {
|
||||
factories[name] = f
|
||||
}
|
||||
|
||||
func GetFactory(name string) StoreFactory {
|
||||
return factories[name]
|
||||
}
|
||||
|
||||
func MakeStore(name string, conf config.Config) (Store, error) {
|
||||
f, ok := factories[name]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("%w: %s", ErrNoFactory, name)
|
||||
}
|
||||
return f(conf)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue