datarhei-dragonfork-core/config/store/dummy.go

74 lines
1.1 KiB
Go
Raw Normal View History

package store
2022-05-13 13:26:45 -04:00
import (
"fmt"
"github.com/datarhei/core/v16/config"
)
2022-05-13 13:26:45 -04:00
2022-07-22 02:33:38 -04:00
type dummyStore struct {
current *config.Config
active *config.Config
2022-07-22 02:33:38 -04:00
}
2022-05-13 13:26:45 -04:00
// NewDummyStore returns a store that returns the default config
func NewDummy() Store {
2022-07-22 02:33:38 -04:00
s := &dummyStore{}
cfg := config.New()
2022-07-22 02:33:38 -04:00
cfg.DB.Dir = "."
cfg.FFmpeg.Binary = "true"
cfg.Storage.Disk.Dir = "."
cfg.Storage.MimeTypes = ""
s.current = cfg
cfg = config.New()
2022-07-22 02:33:38 -04:00
cfg.DB.Dir = "."
cfg.FFmpeg.Binary = "true"
cfg.Storage.Disk.Dir = "."
cfg.Storage.MimeTypes = ""
s.active = cfg
return s
2022-05-13 13:26:45 -04:00
}
func (c *dummyStore) Get() *config.Config {
return c.current.Clone()
2022-05-13 13:26:45 -04:00
}
func (c *dummyStore) Set(d *config.Config) error {
2022-05-13 13:26:45 -04:00
d.Validate(true)
if d.HasErrors() {
return fmt.Errorf("configuration data has errors after validation")
}
c.current = d.Clone()
2022-07-22 02:33:38 -04:00
2022-05-13 13:26:45 -04:00
return nil
}
func (c *dummyStore) GetActive() *config.Config {
return c.active.Clone()
2022-05-13 13:26:45 -04:00
}
func (c *dummyStore) SetActive(d *config.Config) error {
2022-05-13 13:26:45 -04:00
d.Validate(true)
if d.HasErrors() {
return fmt.Errorf("configuration data has errors after validation")
}
c.active = d.Clone()
2022-07-22 02:33:38 -04:00
2022-05-13 13:26:45 -04:00
return nil
}
func (c *dummyStore) Reload() error {
return nil
}