diff --git a/internal/settings/settings.go b/internal/settings/settings.go index 988a763..acb4ae4 100644 --- a/internal/settings/settings.go +++ b/internal/settings/settings.go @@ -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"` -} \ No newline at end of file + 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 +}