Preliminary settings support (from TOML).

This commit is contained in:
Benjamin A. Shelton 2026-09-09 22:14:55 -06:00
commit 704a17717d
Signed by: zancarius
GPG key ID: 8BD42DBD6C337E01

View file

@ -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
}