config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package config provides Viper configuration loading utilities.

Index

Constants

View Source
const (
	// JSONLogFormat indicates JSON log format.
	JSONLogFormat = "json"
	// TextLogFormat indicates text log format.
	TextLogFormat = "text"
)

Variables

This section is empty.

Functions

func Load

func Load(configPath string, isFile bool, cfg *LoaderConfig) error

Load reads configuration from file and environment variables. If configPath is empty, it searches in default paths. If isFile is true, configPath is treated as a direct file path.

func ValidateRequired

func ValidateRequired(fields map[string]string) error

ValidateRequired checks that required configuration fields are set.

func ValidateSessionKeys

func ValidateSessionKeys() error

ValidateSessionKeys validates that session keys are the correct length.

Types

type BaseConfig

type BaseConfig struct {
	ListenAddr       string        `mapstructure:"listen_addr"`
	AdvertiseURL     string        `mapstructure:"advertise_url"`
	AdminModeTimeout time.Duration `mapstructure:"admin_mode_timeout"`

	Session  SessionConfig  `mapstructure:"session"`
	Database DatabaseConfig `mapstructure:"database"`
	Redis    RedisConfig    `mapstructure:"redis"`
	Worker   WorkerConfig   `mapstructure:"worker"`
	OIDC     OIDCConfig     `mapstructure:"oidc"`
	Logging  LogConfig      `mapstructure:"logging"`
	SMTP     SMTPConfig     `mapstructure:"smtp"`
}

BaseConfig holds common configuration fields used by juango applications.

func GetBaseConfig

func GetBaseConfig() *BaseConfig

GetBaseConfig returns the base configuration from Viper. Applications should call this after Load() and extend with their own fields.

type DatabaseConfig

type DatabaseConfig struct {
	Path              string `mapstructure:"path"`
	WriteAheadLog     bool   `mapstructure:"write_ahead_log"`
	WALAutoCheckPoint int    `mapstructure:"wal_auto_check_point"`
}

DatabaseConfig holds database configuration.

type LoaderConfig

type LoaderConfig struct {
	// EnvPrefix is the prefix for environment variables (e.g., "MYAPP" -> MYAPP_LISTEN_ADDR).
	EnvPrefix string

	// ConfigPaths is a list of directories to search for config files.
	ConfigPaths []string

	// ConfigName is the name of the config file (without extension).
	ConfigName string

	// Defaults is a map of default values.
	Defaults map[string]interface{}
}

LoaderConfig holds configuration for the config loader.

func DefaultLoaderConfig

func DefaultLoaderConfig(envPrefix string) *LoaderConfig

DefaultLoaderConfig returns default loader configuration.

type LogConfig

type LogConfig struct {
	Format     string        `mapstructure:"format"`
	Level      zerolog.Level `mapstructure:"level"`
	WithCaller bool          `mapstructure:"with_caller"`
}

LogConfig holds logging configuration.

func GetLogConfig

func GetLogConfig() LogConfig

GetLogConfig returns the logging configuration from Viper.

type OIDCConfig

type OIDCConfig struct {
	Issuer       string            `mapstructure:"issuer"`
	ClientID     string            `mapstructure:"client_id"`
	ClientSecret string            `mapstructure:"client_secret"`
	Scopes       []string          `mapstructure:"scopes"`
	ExtraParams  map[string]string `mapstructure:"extra_params"`
	Expiry       time.Duration     `mapstructure:"expiry"`
}

OIDCConfig holds OIDC authentication configuration.

type RedisConfig

type RedisConfig struct {
	Addr     string `mapstructure:"addr"`
	Password string `mapstructure:"password"`
	DB       int    `mapstructure:"db"`
}

RedisConfig holds Redis configuration for background tasks.

type SMTPConfig

type SMTPConfig struct {
	Host     string `mapstructure:"host"`
	Port     int    `mapstructure:"port"`
	User     string `mapstructure:"user"`
	Password string `mapstructure:"password"`
	From     string `mapstructure:"from_address"`
	ReplyTo  string `mapstructure:"reply_to"`
}

SMTPConfig holds SMTP email configuration.

type SessionConfig

type SessionConfig struct {
	AuthenticationKey string        `mapstructure:"authentication_key"`
	EncryptionKey     string        `mapstructure:"encryption_key"`
	CookieName        string        `mapstructure:"cookie_name"`
	CookieExpiry      time.Duration `mapstructure:"cookie_expiry"`
}

SessionConfig holds session configuration.

type WorkerConfig

type WorkerConfig struct {
	Concurrency int `mapstructure:"concurrency"`
}

WorkerConfig holds background worker configuration.

Jump to

Keyboard shortcuts

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