package config import ( "log/slog" "github.com/BurntSushi/toml" ) type Config struct { ServerConfig ServerConfig `toml:"SERVICE"` BaseURL string `toml:"BASE_URL"` SessionLifetime int `toml:"SESSION_LIFETIME_SECONDS"` CookieSecret string `toml:"COOKIE_SECRET"` LLMConfig LLMConfig `toml:"LLM"` } type ServerConfig struct { Host string `toml:"HOST"` Port string `toml:"PORT"` } type LLMConfig struct { URL string `toml:"LLM_URL"` TOKEN string `toml:"LLM_TOKEN"` } func LoadConfigOrDefault(fn string) *Config { if fn == "" { fn = "config.toml" } config := &Config{} _, err := toml.DecodeFile(fn, &config) if err != nil { slog.Warn("failed to read config from file, loading default", "error", err) config.BaseURL = "https://localhost:3000" config.SessionLifetime = 30000 config.CookieSecret = "test" config.ServerConfig.Host = "localhost" config.ServerConfig.Port = "3000" } return config }