51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"os"
|
|
)
|
|
|
|
type Config struct {
|
|
ContentDir string
|
|
KeysDir string
|
|
Port string
|
|
RepoURL string
|
|
RepoToken string
|
|
WebhookSecret string
|
|
NtfyURL string
|
|
NtfyTopic string
|
|
EnableWebhook bool
|
|
}
|
|
|
|
func loadConfig() *Config {
|
|
cfg := &Config{}
|
|
|
|
flag.StringVar(&cfg.ContentDir, "content-dir", envOrDefault("CONTENT_DIR", "./content"), "directory to serve as content")
|
|
flag.StringVar(&cfg.KeysDir, "keys-dir", envOrDefault("KEYS_DIR", "./keys"), "directory to serve as WKD keys")
|
|
flag.StringVar(&cfg.Port, "port", envOrDefault("PORT", "80"), "port to listen on")
|
|
flag.StringVar(&cfg.RepoURL, "repo-url", envOrDefault("REPO_URL", ""), "git repo URL for webhook auto-update")
|
|
flag.StringVar(&cfg.RepoToken, "repo-token", envOrDefault("REPO_TOKEN", ""), "git repo access token")
|
|
flag.StringVar(&cfg.WebhookSecret, "webhook-secret", envOrDefault("WEBHOOK_SECRET", ""), "HMAC secret for webhook validation")
|
|
flag.StringVar(&cfg.NtfyURL, "ntfy-url", envOrDefault("NTFY_URL", ""), "ntfy server URL for failure notifications")
|
|
flag.StringVar(&cfg.NtfyTopic, "ntfy-topic", envOrDefault("NTFY_TOPIC", ""), "ntfy topic for failure notifications")
|
|
flag.BoolVar(&cfg.EnableWebhook, "webhook", envOrDefaultBool("ENABLE_WEBHOOK", false), "enable git-webhook auto-update feature")
|
|
|
|
flag.Parse()
|
|
return cfg
|
|
}
|
|
|
|
func envOrDefault(key, def string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|
|
|
|
func envOrDefaultBool(key string, def bool) bool {
|
|
v := os.Getenv(key)
|
|
if v == "" {
|
|
return def
|
|
}
|
|
return v == "true" || v == "1"
|
|
}
|