// Package config resolves runtime configuration from flags and environment. // Flags win over env; env wins over defaults. package config import ( "flag" "os" ) type Config struct { ReposPath string // directory holding bare *.git repos ListenAddr string // host:port to listen on BaseURL string // public base URL (for absolute links, feeds) SoftServeHTTP string // Soft Serve HTTP clone base, reverse-proxied at /git in prod SoftServeDB string // path to soft-serve.db; when set, only public repos are served WebhookSecret string // shared secret for the Soft Serve release webhook (empty disables it) DLPath string // directory where release tarballs are written (served at /dl) TapRepo string // bare repo name of the Homebrew tap (default "homebrew-tap") StatusSecret string // shared secret for the CLI status endpoint (empty disables /status) StatePath string // JSON file storing per-repo deploy status } // Load parses the `serve` flags (with env fallbacks) from args and returns the // config. Pass the subcommand's arguments (os.Args[2:]). func Load(args []string) Config { fs := flag.NewFlagSet("serve", flag.ExitOnError) var c Config fs.StringVar(&c.ReposPath, "repos", env("REPOS_PATH", "./repos"), "directory of bare *.git repositories") fs.StringVar(&c.ListenAddr, "addr", env("LISTEN_ADDR", ":8080"), "listen address") fs.StringVar(&c.BaseURL, "base-url", env("BASE_URL", "http://localhost:8080"), "public base URL") fs.StringVar(&c.SoftServeHTTP, "soft-serve-http", env("SOFT_SERVE_HTTP", "http://localhost:23232"), "git clone base shown in the UI footer (e.g. https://your-host/git)") fs.StringVar(&c.SoftServeDB, "soft-serve-db", env("SOFT_SERVE_DB", ""), "path to soft-serve.db; when set, only public (non-private, non-hidden) repos are served") fs.StringVar(&c.WebhookSecret, "webhook-secret", env("WEBHOOK_SECRET", ""), "shared secret for the Soft Serve release webhook (empty disables /hooks/release)") fs.StringVar(&c.DLPath, "dl-path", env("DL_PATH", "/var/lib/custard/dl"), "directory where release tarballs are written") fs.StringVar(&c.TapRepo, "tap-repo", env("TAP_REPO", "homebrew-tap"), "bare repo name of the Homebrew tap") fs.StringVar(&c.StatusSecret, "status-secret", env("STATUS_SECRET", ""), "shared secret for the CLI status endpoint (empty disables /status)") fs.StringVar(&c.StatePath, "state-path", env("STATE_PATH", "/var/lib/custard/state/status.json"), "JSON file storing per-repo deploy status") _ = fs.Parse(args) return c } func env(key, def string) string { if v := os.Getenv(key); v != "" { return v } return def }