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