package config import ( "io/fs" "log/slog" "github.com/BurntSushi/toml" "github.com/pkg/errors" ) type Taxonomy struct { Name string Feed bool } type MenuItem struct { Name string URL string `toml:"url"` } type Config struct { DefaultLanguage string `toml:"default_language"` BaseURL string `toml:"base_url"` RedirectOtherHostnames bool `toml:"redirect_other_hostnames"` Title string Email string Description string DomainStartDate string `toml:"domain_start_date"` OriginalDomain string `toml:"original_domain"` Taxonomies []Taxonomy Extra struct { Headers map[string]string } Menus map[string][]MenuItem } func GetConfig() (*Config, error) { config := Config{} slog.Debug("reading config.toml") _, err := toml.DecodeFile("config.toml", &config) if err != nil { var pathError *fs.PathError var tomlError toml.ParseError if errors.As(err, &pathError) { return nil, errors.WithMessage(err, "could not read configuration") } else if errors.As(err, &tomlError) { return nil, errors.WithMessage(err, tomlError.ErrorWithUsage()) } else { return nil, errors.Wrap(err, "config error") } } return &config, nil }