Update binary name, DB path, session cookie, deploy scripts, systemd service, Docker config, CI workflow, and .dockerignore. Remove stale Claude command and settings files.
77 lines
1.4 KiB
Go
77 lines
1.4 KiB
Go
// Package config provides build-tag-switched application configuration.
|
|
// The global Config singleton is initialized at import time via init()
|
|
// and can be overridden in tests with LoadForTest().
|
|
package config
|
|
|
|
import (
|
|
"log/slog"
|
|
"os"
|
|
"sync"
|
|
|
|
"github.com/joho/godotenv"
|
|
"github.com/rs/zerolog"
|
|
)
|
|
|
|
type Environment string
|
|
|
|
const (
|
|
Dev Environment = "dev"
|
|
Prod Environment = "prod"
|
|
)
|
|
|
|
type Config struct {
|
|
Environment Environment
|
|
Host string
|
|
Port string
|
|
LogLevel zerolog.Level
|
|
AppURL string
|
|
DBPath string
|
|
}
|
|
|
|
var (
|
|
Global *Config
|
|
once sync.Once
|
|
)
|
|
|
|
func init() {
|
|
once.Do(func() {
|
|
Global = Load()
|
|
})
|
|
}
|
|
|
|
func getEnv(key, fallback string) string {
|
|
if val, ok := os.LookupEnv(key); ok {
|
|
return val
|
|
}
|
|
return fallback
|
|
}
|
|
|
|
func loadBase() *Config {
|
|
if err := godotenv.Load(); err != nil {
|
|
slog.Warn("no .env file found, using environment variables and defaults")
|
|
}
|
|
|
|
return &Config{
|
|
Host: getEnv("HOST", "0.0.0.0"),
|
|
Port: getEnv("PORT", "7331"),
|
|
LogLevel: func() zerolog.Level {
|
|
switch os.Getenv("LOG_LEVEL") {
|
|
case "TRACE":
|
|
return zerolog.TraceLevel
|
|
case "DEBUG":
|
|
return zerolog.DebugLevel
|
|
case "INFO":
|
|
return zerolog.InfoLevel
|
|
case "WARN":
|
|
return zerolog.WarnLevel
|
|
case "ERROR":
|
|
return zerolog.ErrorLevel
|
|
default:
|
|
return zerolog.InfoLevel
|
|
}
|
|
}(),
|
|
AppURL: getEnv("APP_URL", "https://games.adriatica.io"),
|
|
DBPath: getEnv("DB_PATH", "data/games.db"),
|
|
}
|
|
}
|