Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0, MIT Imports: 16 Imported by: 0

Documentation

Overview

Package config loads runtime settings in layers; later layers win:

defaults → --env-file → system env → overrides

Empty values do not shadow defaults. Unknown keys fail in the env file but are ignored in the system environment.

Index

Constants

This section is empty.

Variables

View Source
var (
	AppName    = "tango"
	AppVersion = "0.0.0"
	BuildHash  = "unknown"
	BuildDate  = "0000-00-00T00:00:00Z"
	Platform   = fmt.Sprintf("%s/%s", runtime.GOOS, runtime.GOARCH)
)

Functions

This section is empty.

Types

type AppConfig

type AppConfig struct {
	Mode         string `koanf:"mode"`
	DataDir      string `koanf:"data_dir"`
	LogLevel     string `koanf:"log_level"`
	LogTransport string `koanf:"log_transport"`
	LogFormat    string `koanf:"log_format"`
	SecretKey    string `koanf:"secret_key"`
}

type AuthConfig

type AuthConfig struct {
	PrivateKey string `koanf:"private_key"`
	PublicKey  string `koanf:"public_key"`
	SecretKey  string `koanf:"secret_key"`

	// AccessTokenExpiry bounds the internal bearer JWT the SPA sends
	// on RPC calls; refresh stays cookie-only.
	AccessTokenExpiry int `koanf:"access_token_expiry"`
	// SessionLifetime bounds a session issued with "remember me".
	SessionLifetime int `koanf:"session_lifetime"`
	// SessionShortLifetime bounds a session issued without "remember
	// me"; it must not exceed SessionLifetime.
	SessionShortLifetime int `koanf:"session_short_lifetime"`

	GithubClientID     string `koanf:"github_client_id"`
	GithubClientSecret string `koanf:"github_client_secret"`
	GoogleClientID     string `koanf:"google_client_id"`
	GoogleClientSecret string `koanf:"google_client_secret"`
}

AuthConfig holds the internal authentication lifetimes. Every duration is in seconds, matching the rest of the environment surface.

type Config

type Config struct {
	Host     string         `koanf:"host"`
	Port     int            `koanf:"port"`
	App      AppConfig      `koanf:"app"`
	Auth     AuthConfig     `koanf:"auth"`
	Database DatabaseConfig `koanf:"database"`
	Mailer   MailerConfig   `koanf:"mailer"`
	OIDC     OIDCConfig     `koanf:"oidc"`
	Public   PublicConfig   `koanf:"public"`
	Queue    QueueConfig    `koanf:"queue"`
	Storage  StorageConfig  `koanf:"storage"`
}

Config defines runtime settings and their koanf keys.

func Load

func Load(opts LoadOptions) (*Config, error)

Load assembles layered config and decodes it into Config.

func (*Config) BackupDir

func (c *Config) BackupDir() string

BackupDir returns the backup directory.

func (*Config) DataDir

func (c *Config) DataDir() string

DataDir returns the configured data root.

func (*Config) KeysDir

func (c *Config) KeysDir() string

KeysDir returns the generated key directory.

func (*Config) LogFile

func (c *Config) LogFile() string

LogFile returns the application log path.

func (*Config) PrivateKeyPath

func (c *Config) PrivateKeyPath() string

PrivateKeyPath returns the private key path.

func (*Config) PublicKeyPath

func (c *Config) PublicKeyPath() string

PublicKeyPath returns the public key path.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks values that defaults cannot express, then reports all errors.

type DatabaseConfig

type DatabaseConfig struct {
	URL string `koanf:"url"`
}

type LoadOptions

type LoadOptions struct {
	// EnvFile is an optional dotenv file between defaults and env.
	EnvFile string

	// Overrides win over everything (resolved CLI flags).
	Overrides map[string]any
}

LoadOptions configures Load.

type MailerConfig

type MailerConfig struct {
	FromEmail    string `koanf:"from_email"`
	FromName     string `koanf:"from_name"`
	SMTPHost     string `koanf:"smtp_host"`
	SMTPPort     int    `koanf:"smtp_port"`
	SMTPUsername string `koanf:"smtp_username"`
	SMTPPassword string `koanf:"smtp_password"`
	SMTPSecure   bool   `koanf:"smtp_secure"`
}

type OIDCConfig added in v0.0.12

type OIDCConfig struct {
	// AccessTokenExpiry and RefreshTokenExpiry are the provider
	// defaults for clients without their own durations.
	AccessTokenExpiry  int `koanf:"access_token_expiry"`
	RefreshTokenExpiry int `koanf:"refresh_token_expiry"`
	// AuthorizationCodeExpiry bounds the one-time code lifetime.
	AuthorizationCodeExpiry int `koanf:"authorization_code_expiry"`
	// InteractionExpiry bounds the sign-in/consent bridge.
	InteractionExpiry int `koanf:"interaction_expiry"`
	// DeviceCodeExpiry bounds the device authorization window
	// (RFC 8628 6.1).
	DeviceCodeExpiry int `koanf:"device_code_expiry"`
	// PARExpiry bounds a pushed authorization request_uri lifetime
	// (RFC 9126 3.2.2 recommends keeping it short).
	PARExpiry int `koanf:"par_expiry"`
}

OIDCConfig holds the relying-party protocol lifetimes. A client's own access/refresh durations override the two token defaults.

type PublicConfig

type PublicConfig struct {
	BaseURL         string   `koanf:"base_url"`
	S3AssetsURL     string   `koanf:"s3_assets_url"`
	VersionCheckURL string   `koanf:"version_check_url"`
	TrustedOrigins  []string `koanf:"trusted_origins"`
}

type QueueConfig

type QueueConfig struct {
	Workers         int `koanf:"workers"`
	ReleaseAfter    int `koanf:"release_after"`
	CleanupInterval int `koanf:"cleanup_interval"`
}

type StorageConfig

type StorageConfig struct {
	DataDir            string  `koanf:"data_dir"`
	MaxUploadSize      int64   `koanf:"max_upload_size"`
	S3AccessKeyID      string  `koanf:"s3_access_key_id"`
	S3BucketDefault    string  `koanf:"s3_bucket_default"`
	S3EndpointURL      string  `koanf:"s3_endpoint_url"`
	S3ForcePathStyle   bool    `koanf:"s3_force_path_style"`
	S3PathPrefix       *string `koanf:"s3_path_prefix"`
	S3Region           string  `koanf:"s3_region"`
	S3SecretAccessKey  string  `koanf:"s3_secret_access_key"`
	S3SignedURLExpires int     `koanf:"s3_signed_url_expires"`
}

Jump to

Keyboard shortcuts

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