combluotion/store/factory.go
Dan Jones e7b88bcc09 Improve Store
Still need to fill out SQLite bootstrap

Also setup plug-in system mechanism
2024-09-14 20:37:51 -05:00

34 lines
609 B
Go

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)
}