▍ humdrum codex / custard
license AGPL-3.0
2.0 KB raw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// 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")
}

// Load parses flags (with env fallbacks) and returns the config.
func Load() Config {
	var c Config
	flag.StringVar(&c.ReposPath, "repos", env("REPOS_PATH", "./repos"), "directory of bare *.git repositories")
	flag.StringVar(&c.ListenAddr, "addr", env("LISTEN_ADDR", ":8080"), "listen address")
	flag.StringVar(&c.BaseURL, "base-url", env("BASE_URL", "http://localhost:8080"), "public base URL")
	flag.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)")
	flag.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")
	flag.StringVar(&c.WebhookSecret, "webhook-secret", env("WEBHOOK_SECRET", ""), "shared secret for the Soft Serve release webhook (empty disables /hooks/release)")
	flag.StringVar(&c.DLPath, "dl-path", env("DL_PATH", "/var/lib/custard/dl"), "directory where release tarballs are written")
	flag.StringVar(&c.TapRepo, "tap-repo", env("TAP_REPO", "homebrew-tap"), "bare repo name of the Homebrew tap")
	flag.Parse()
	return c
}

func env(key, def string) string {
	if v := os.Getenv(key); v != "" {
		return v
	}
	return def
}