filebrowser/bolt/config.go

27 lines
581 B
Go
Raw Normal View History

2017-08-19 19:35:44 +08:00
package bolt
import (
"github.com/asdine/storm"
2017-08-20 15:42:38 +08:00
fm "github.com/hacdias/filemanager"
2017-08-19 19:35:44 +08:00
)
2017-08-20 16:27:03 +08:00
// ConfigStore is a configuration store.
2017-08-19 19:35:44 +08:00
type ConfigStore struct {
DB *storm.DB
}
2017-08-20 16:27:03 +08:00
// Get gets a configuration from the database to an interface.
2017-08-19 19:35:44 +08:00
func (c ConfigStore) Get(name string, to interface{}) error {
2017-08-20 15:42:38 +08:00
err := c.DB.Get("config", name, to)
if err == storm.ErrNotFound {
return fm.ErrNotExist
}
return err
2017-08-19 19:35:44 +08:00
}
2017-08-20 16:27:03 +08:00
// Save saves a configuration from an interface to the database.
2017-08-19 19:35:44 +08:00
func (c ConfigStore) Save(name string, from interface{}) error {
return c.DB.Set("config", name, from)
}