datarhei-dragonfork-core/config/dummy.go

84 lines
1.3 KiB
Go
Raw Normal View History

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