package main import ( "fmt" "os" "strings" logger "git.site.quack-lab.dev/dave/cylogger" "github.com/joho/godotenv" ) var options Options func init() { var err error options, err = LoadOptions() if err != nil { logger.Error("Failed to load options %v", err) return } } type Options struct { ClientID string RedirectURI string Scopes []string DBPath string Port string } func LoadOptions() (Options, error) { // Load environment variables strictly from .env file (fail if there's an error loading) if err := godotenv.Load(); err != nil { return Options{}, fmt.Errorf("error loading .env file: %w", err) } clientID := os.Getenv("ESI_CLIENT_ID") if clientID == "" { return Options{}, fmt.Errorf("ESI_CLIENT_ID is required in .env file") } redirectURI := os.Getenv("ESI_REDIRECT_URI") if redirectURI == "" { return Options{}, fmt.Errorf("ESI_REDIRECT_URI is required in .env file") } rawScopes := os.Getenv("ESI_SCOPES") if rawScopes == "" { return Options{}, fmt.Errorf("ESI_SCOPES is required in .env file") } scopes := strings.Fields(rawScopes) dbPath := os.Getenv("DB_PATH") if dbPath == "" { return Options{}, fmt.Errorf("DB_PATH is required in .env file") } port := os.Getenv("HTTP_SERVER_PORT") if port == "" { return Options{}, fmt.Errorf("HTTP_SERVER_PORT is required in .env file") } return Options{ ClientID: clientID, RedirectURI: redirectURI, Scopes: scopes, DBPath: dbPath, Port: port, }, nil }