Preliminary settings support (from TOML).
This commit is contained in:
parent
49260b79dc
commit
704a17717d
1 changed files with 31 additions and 9 deletions
|
|
@ -1,21 +1,24 @@
|
|||
package settings
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"os"
|
||||
|
||||
"github.com/pelletier/go-toml"
|
||||
)
|
||||
|
||||
type Setting struct {
|
||||
API API
|
||||
type Settings struct {
|
||||
API API
|
||||
DailyScripture DailyScripture `toml:"daily_scripture"`
|
||||
System System
|
||||
Translations Translations
|
||||
System System
|
||||
Translations Translations
|
||||
}
|
||||
|
||||
type API struct {
|
||||
BaseURL string `toml:"base_url"`
|
||||
BaseURL string `toml:"base_url"`
|
||||
Schedule string
|
||||
Rotation string
|
||||
User string
|
||||
User string
|
||||
}
|
||||
|
||||
type DailyScripture struct {
|
||||
|
|
@ -27,6 +30,25 @@ type System struct {
|
|||
}
|
||||
|
||||
type Translations struct {
|
||||
BaseDir string `toml:"basedir"`
|
||||
Active []string `toml:"active"`
|
||||
}
|
||||
BaseDir string `toml:"basedir"`
|
||||
Active []string `toml:"active"`
|
||||
}
|
||||
|
||||
func LoadSettings(name string) (*Settings, error) {
|
||||
conf := &Settings{}
|
||||
|
||||
buf, err := os.ReadFile(name)
|
||||
if err != nil {
|
||||
if _, ok := err.(*fs.PathError); ok {
|
||||
return nil, ErrSettingsNotFound.Do(err)
|
||||
}
|
||||
return nil, ErrReadingSettings.Do(err)
|
||||
}
|
||||
|
||||
err = toml.Unmarshal(buf, conf)
|
||||
if err != nil {
|
||||
return nil, ErrReadingSettings.Do(err)
|
||||
}
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue