Files
vibeproxy/internal/config/config.go
T
owenandClaude Sonnet 5 ba1f7c4c03 Initial vibeproxy implementation
Self-contained HTTP/HTTPS/TCP/UDP reverse proxy manager written in Go,
with SQLite storage, a Bootstrap 5 admin UI (Go templates, no JS
framework), and a REST API under /api/v1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QTXFrNP1imCW7jtfL5SZrw
2026-08-17 10:28:59 -05:00

48 lines
1.6 KiB
Go

// Package config holds process bootstrap configuration: everything needed
// before the database is even open. Runtime/admin-tunable settings (ACME
// email, retention, trusted proxies, etc.) live in the database instead —
// see internal/database's settings table — so they can change without a
// restart.
package config
import (
"flag"
"os"
)
type Config struct {
DataDir string
DBPath string
HTTPAddr string
HTTPSAddr string
AdminAddr string
}
func Default() Config {
return Config{
DataDir: "./data",
DBPath: "./data/vibeproxy.db",
HTTPAddr: ":80",
HTTPSAddr: ":443",
AdminAddr: ":8081",
}
}
// RegisterFlags binds cfg's fields to flags on fs, seeded from environment
// variables (VIBEPROXY_*) so the same binary works under systemd or Docker
// without a wrapper script.
func RegisterFlags(fs *flag.FlagSet, cfg *Config) {
fs.StringVar(&cfg.DataDir, "data-dir", envOr("VIBEPROXY_DATA_DIR", cfg.DataDir), "directory for the database, certificates, and backups")
fs.StringVar(&cfg.DBPath, "db-path", envOr("VIBEPROXY_DB_PATH", cfg.DBPath), "path to the SQLite database file")
fs.StringVar(&cfg.HTTPAddr, "http-addr", envOr("VIBEPROXY_HTTP_ADDR", cfg.HTTPAddr), "address for the plain HTTP proxy listener")
fs.StringVar(&cfg.HTTPSAddr, "https-addr", envOr("VIBEPROXY_HTTPS_ADDR", cfg.HTTPSAddr), "address for the HTTPS proxy listener")
fs.StringVar(&cfg.AdminAddr, "admin-addr", envOr("VIBEPROXY_ADMIN_ADDR", cfg.AdminAddr), "address for the admin web UI, REST API, and /metrics, /healthz, /readyz")
}
func envOr(key, def string) string {
if v := os.Getenv(key); v != "" {
return v
}
return def
}