go-tell/internal/config/config.go

31 lines
907 B
Go
Raw Normal View History

package config
import (
"os"
)
2026-09-19 16:45:24 +02:00
// Config carries the runtime settings for the CMS. The application database is
// the only datastore: identities and sessions belong to the upstream SSO proxy.
type Config struct {
2026-09-19 16:45:24 +02:00
HTTPAddr, ApplicationDatabaseURL string
AllowedOrigins, SSOHeader, SSOToken, SSOCookie string
}
2026-09-19 16:45:24 +02:00
func Load() Config {
2026-09-19 14:48:42 +02:00
return Config{
HTTPAddr: get("CMS_HTTP_ADDR", ":8080"),
ApplicationDatabaseURL: get("CMS_APPLICATION_DATABASE_URL", "host=localhost user=cms password=cms dbname=cms port=5432 sslmode=disable"),
AllowedOrigins: get("CMS_ALLOWED_ORIGINS", "http://localhost:5173"),
2026-09-19 16:45:24 +02:00
SSOHeader: get("CMS_SSO_HEADER", "X-SSO-Token"),
SSOToken: get("CMS_SSO_TOKEN", ""),
SSOCookie: get("CMS_SSO_COOKIE", ""),
2026-09-19 14:48:42 +02:00
}
}
2026-09-19 16:45:24 +02:00
func get(k, d string) string {
if v := os.Getenv(k); v != "" {
return v
}
return d
}