2017-10-30 15:47:59 +00:00
|
|
|
package bolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/asdine/storm"
|
2018-04-23 21:42:52 +00:00
|
|
|
fb "github.com/filebrowser/filebrowser"
|
2017-10-30 15:47:59 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ConfigStore is a configuration store.
|
|
|
|
type ConfigStore struct {
|
|
|
|
DB *storm.DB
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get gets a configuration from the database to an interface.
|
|
|
|
func (c ConfigStore) Get(name string, to interface{}) error {
|
|
|
|
err := c.DB.Get("config", name, to)
|
|
|
|
if err == storm.ErrNotFound {
|
2018-04-23 21:42:52 +00:00
|
|
|
return fb.ErrNotExist
|
2017-10-30 15:47:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Save saves a configuration from an interface to the database.
|
|
|
|
func (c ConfigStore) Save(name string, from interface{}) error {
|
|
|
|
return c.DB.Set("config", name, from)
|
|
|
|
}
|