store: now opening stores

This commit is contained in:
Leo Balduf 2016-02-16 21:47:40 +01:00 committed by Jimmy Zelinskie
parent 1dab3978fb
commit 1a4ecb133f
3 changed files with 26 additions and 14 deletions

View file

@ -36,13 +36,10 @@ func RegisterClientStoreDriver(name string, driver ClientStoreDriver) {
}
// OpenClientStore returns a ClientStore specified by a configuration.
func OpenClientStore(name string, cfg *Config) (ClientStore, error) {
driver, ok := clientStoreDrivers[name]
func OpenClientStore(cfg *Config) (ClientStore, error) {
driver, ok := clientStoreDrivers[cfg.ClientStore]
if !ok {
return nil, fmt.Errorf(
"store: unknown driver %q (forgotten import?)",
name,
)
return nil, fmt.Errorf("store: unknown driver %q (forgotten import?)", cfg.ClientStore)
}
return driver.New(cfg)

View file

@ -49,13 +49,10 @@ func RegisterPeerStoreDriver(name string, driver PeerStoreDriver) {
}
// OpenPeerStore returns a PeerStore specified by a configuration.
func OpenPeerStore(name string, cfg *Config) (PeerStore, error) {
driver, ok := peerStoreDrivers[name]
func OpenPeerStore(cfg *Config) (PeerStore, error) {
driver, ok := peerStoreDrivers[cfg.PeerStore]
if !ok {
return nil, fmt.Errorf(
"storage: unknown driver %q (forgotten import?)",
name,
)
return nil, fmt.Errorf("storage: unknown driver %q (forgotten import?)", cfg.PeerStore)
}
return driver.New(cfg)

View file

@ -30,9 +30,27 @@ func constructor(srvcfg *config.ServerConfig, tkr *tracker.Tracker) (server.Serv
return nil, errors.New("store: invalid store config: " + err.Error())
}
cs, err := OpenClientStore(cfg)
if err != nil {
return nil, err
}
ps, err := OpenPeerStore(cfg)
if err != nil {
return nil, err
}
ips, err := OpenIPStore(cfg)
if err != nil {
return nil, err
}
theStore = &Store{
cfg: cfg,
tkr: tkr,
cfg: cfg,
tkr: tkr,
ClientStore: cs,
PeerStore: ps,
IPStore: ips,
}
}
return theStore, nil