config

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package config owns the layered configuration loader.

Precedence (lowest → highest):

  1. Built-in defaults (this file)
  2. TOML file (path from $SHITHUB_CONFIG, falling back to /etc/shithub/config.toml)
  3. Environment variables (SHITHUB_<area>_<key>; nested keys joined with "__")
  4. CLI flag overrides handed in by the caller

The Config struct is the single source of truth for what is configurable. Every consumer reads from this struct rather than from os.Getenv directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PrintRedacted

func PrintRedacted(c Config) (string, error)

PrintRedacted writes the config to w in TOML form with secrets replaced by `***`. The transformation operates on a deep copy so the live Config is never mutated.

func Validate

func Validate(c *Config) error

Validate enforces invariants. Errors are precise enough to point at the offending key.

Types

type Argon2Config

type Argon2Config struct {
	MemoryKiB uint32 `toml:"memory_kib"`
	Time      uint32 `toml:"time"`
	Threads   uint8  `toml:"threads"`
}

Argon2Config tunes the password hasher's cost. Defaults match the internal/auth/password Defaults() — operators bump these on faster hardware to keep the per-hash cost in the 100–300 ms band.

type AuthConfig

type AuthConfig struct {
	RequireEmailVerification bool           `toml:"require_email_verification"`
	BaseURL                  string         `toml:"base_url"` // e.g. https://shithub.example
	SiteName                 string         `toml:"site_name"`
	EmailFrom                string         `toml:"email_from"`
	EmailBackend             string         `toml:"email_backend"` // stdout | smtp | postmark
	SMTP                     SMTPConfig     `toml:"smtp"`
	Postmark                 PostmarkConfig `toml:"postmark"`
	Argon2                   Argon2Config   `toml:"argon2"`
	TOTPKeyB64               string         `toml:"totp_key_b64"` // base64 32-byte AEAD key for at-rest TOTP secrets
}

AuthConfig configures the email/password auth surface.

type Config

type Config struct {
	Env            string               `toml:"env"` // "dev", "staging", "prod"
	Web            WebConfig            `toml:"web"`
	DB             DBConfig             `toml:"db"`
	Log            LogConfig            `toml:"log"`
	Metrics        MetricsConfig        `toml:"metrics"`
	Tracing        TracingConfig        `toml:"tracing"`
	ErrorReporting ErrorReportingConfig `toml:"error_reporting"`
	Session        SessionConfig        `toml:"session"`
	Storage        StorageConfig        `toml:"storage"`
	Auth           AuthConfig           `toml:"auth"`
	Notif          NotifConfig          `toml:"notif"`
}

Config is the typed root.

func Defaults

func Defaults() Config

Defaults returns the zero-config baseline.

func Load

func Load(cliOverrides map[string]string) (Config, error)

Load resolves configuration in the documented precedence order. CLI overrides may be nil. The TOML file is optional — its absence is not an error; its existence with bad syntax IS.

type DBConfig

type DBConfig struct {
	URL            string        `toml:"url"`
	MaxConns       int           `toml:"max_conns"`
	MinConns       int           `toml:"min_conns"`
	ConnectTimeout time.Duration `toml:"connect_timeout"`
}

DBConfig holds Postgres settings.

type ErrorReportingConfig

type ErrorReportingConfig struct {
	DSN         string `toml:"dsn"`
	Environment string `toml:"environment"`
	Release     string `toml:"release"`
}

ErrorReportingConfig configures the Sentry/GlitchTip-protocol DSN.

type LogConfig

type LogConfig struct {
	Level  string `toml:"level"`  // debug | info | warn | error
	Format string `toml:"format"` // text (dev) | json (prod)
}

LogConfig holds slog settings.

type MetricsConfig

type MetricsConfig struct {
	Enabled       bool   `toml:"enabled"`
	BasicAuthUser string `toml:"basic_auth_user"`
	BasicAuthPass string `toml:"basic_auth_pass"`
}

MetricsConfig configures the /metrics endpoint.

type NotifConfig

type NotifConfig struct {
	UnsubscribeKeyB64 string `toml:"unsubscribe_key_b64"`
}

NotifConfig configures the S29 notification surface. UnsubscribeKeyB64 is the base64-encoded HMAC-SHA256 key that signs one-click unsubscribe URLs (RFC 8058). When empty (dev default), the fan-out worker derives a deterministic key from the session key so links are stable across restarts without operator action — this derivation is NOT suitable for prod and the wiring layer logs a warning when it fires.

type PostmarkConfig

type PostmarkConfig struct {
	ServerToken string `toml:"server_token"`
}

PostmarkConfig holds Postmark transactional API settings.

type S3StorageConfig

type S3StorageConfig struct {
	Endpoint        string `toml:"endpoint"`          // host[:port], no scheme
	Region          string `toml:"region"`            // e.g. "us-east-1", "nyc3"
	AccessKeyID     string `toml:"access_key_id"`     //
	SecretAccessKey string `toml:"secret_access_key"` //
	Bucket          string `toml:"bucket"`            // e.g. "shithub-dev"
	UseSSL          bool   `toml:"use_ssl"`           // true for Spaces, false for local MinIO
	ForcePathStyle  bool   `toml:"force_path_style"`  // true for MinIO, false for Spaces
}

S3StorageConfig holds the S3-compatible endpoint settings.

type SMTPConfig

type SMTPConfig struct {
	Addr     string `toml:"addr"` // host:port
	Username string `toml:"username"`
	Password string `toml:"password"`
}

SMTPConfig holds plain-SMTP backend settings (e.g. MailHog in dev).

type SessionConfig

type SessionConfig struct {
	KeyB64 string        `toml:"key_b64"`
	MaxAge time.Duration `toml:"max_age"`
	Secure bool          `toml:"secure"`
}

SessionConfig configures the cookie session store.

type StorageConfig

type StorageConfig struct {
	ReposRoot string          `toml:"repos_root"` // filesystem root for bare repos
	S3        S3StorageConfig `toml:"s3"`
}

StorageConfig configures repo filesystem storage and S3-compatible object storage. The S3 block targets MinIO in dev/test and DigitalOcean Spaces in prod (force_path_style true for MinIO, false for Spaces).

type TracingConfig

type TracingConfig struct {
	Enabled     bool    `toml:"enabled"`
	Endpoint    string  `toml:"endpoint"` // OTLP HTTP endpoint
	SampleRate  float64 `toml:"sample_rate"`
	ServiceName string  `toml:"service_name"`
}

TracingConfig configures the OpenTelemetry exporter.

type WebConfig

type WebConfig struct {
	Addr            string        `toml:"addr"`
	ReadTimeout     time.Duration `toml:"read_timeout"`
	WriteTimeout    time.Duration `toml:"write_timeout"`
	ShutdownTimeout time.Duration `toml:"shutdown_timeout"`
}

WebConfig holds HTTP server settings.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL