Files
wotra/internal/config/config.go

46 lines
782 B
Go

package config
import (
"fmt"
"os"
)
// Config holds runtime configuration loaded from environment variables.
type Config struct {
AuthToken string
Port string
DBPath string
Timezone string
}
// Load reads configuration from environment variables, returning an error if
// required variables are missing.
func Load() (*Config, error) {
token := os.Getenv("AUTH_TOKEN")
if token == "" {
return nil, fmt.Errorf("AUTH_TOKEN environment variable is required")
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
dbPath := os.Getenv("DB_PATH")
if dbPath == "" {
dbPath = "wotra.db"
}
tz := os.Getenv("TZ")
if tz == "" {
tz = "UTC"
}
return &Config{
AuthToken: token,
Port: port,
DBPath: dbPath,
Timezone: tz,
}, nil
}