package boot import ( "errors" "fmt" "time" "atlas9.dev/c/mail/mail_ses" "github.com/BurntSushi/toml" ) type Config struct { Server struct { Port int Host string BaseURL string } Database DatabaseConfig Session SessionConfig APIKey APIKeyConfig OAuth struct { Google OAuthProviderConfig Apple OAuthProviderConfig GitHub OAuthProviderConfig Test OAuthProviderConfig } Mail mail_ses.Config } type DatabaseConfig struct { Path string } type SessionConfig struct { Name string Lifetime time.Duration // Secure should be true in production (HTTPS) and false in tests that // use httptest's plain HTTP. Secure bool } type OAuthProviderConfig struct { ClientID string ClientSecret string RedirectURL string } type APIKeyConfig struct { DefaultExpirationHours int GracePeriodHours int AllowedAlgorithms []string } func LoadConfig(path string) (*Config, error) { var config Config if _, err := toml.DecodeFile(path, &config); err != nil { return nil, fmt.Errorf("failed to decode config: %w", err) } if err := config.validate(); err != nil { return nil, err } return &config, nil } func (c *Config) validate() error { var errs []error if c.Server.BaseURL == "" { errs = append(errs, fmt.Errorf("Server.BaseURL is required")) } return errors.Join(errs...) }