Documentation
¶
Index ¶
Constants ¶
const ( // OIDCScopeOpenID is the OIDC scope for OpenID Connect authentication. OIDCScopeOpenID = "openid" // OIDCScopeProfile is the OIDC scope for requesting access to the user's profile information. OIDCScopeProfile = "profile" // OIDCScopeEmail is the OIDC scope for requesting access to the user's email address. OIDCScopeEmail = "email" )
const ( // DefaultDBMaxIdleConn is the default database idle connection count. DefaultDBMaxIdleConn = 5 // DefaultDBMaxOpenConn is the default maximum number of open database connections. DefaultDBMaxOpenConn = 10 // DefaultDBConnMaxLifetime is the default maximum lifetime of a database connection. DefaultDBConnMaxLifetime = 10 * time.Minute )
const ( // DefaultLoggerLevel is the default log level for the application. DefaultLoggerLevel = commonLogger.LogLevelInfo // DefaultLoggerMode is the default log mode for the application. DefaultLoggerMode = commonLogger.LogModePretty )
const ( // DefaultMaxMindAutoUpdate is the default value for automatically updating the MaxMind GeoIP database. DefaultMaxMindAutoUpdate = true // DefaultMaxMindAutoUpdateInterval is the default interval for automatically updating the MaxMind GeoIP database. DefaultMaxMindAutoUpdateInterval = 24 * time.Hour )
const ( // DefaultServerListenAddr is the default server listen address. DefaultServerListenAddr = "0.0.0.0" // DefaultServerListenPort is the default server listen port. DefaultServerListenPort = 5000 // DefaultServerReadTimeout is the default server read timeout. DefaultServerReadTimeout = 15 * time.Second // DefaultServerWriteTimeout is the default server write timeout. DefaultServerWriteTimeout = 15 * time.Second // DefaultServerIdleTimeout is the default server idle timeout. DefaultServerIdleTimeout = 60 * time.Second // DefaultServerWaitTimeout is the default server wait time. DefaultServerWaitTimeout = 15 * time.Second // DefaultServerRequestTimeout is the default request timeout. DefaultServerRequestTimeout = 60 * time.Second )
const (
DefaultAssetDirPath = "./data"
)
Variables ¶
var ( // ErrOIDCIssuerEmpty indicates that the OIDC issuer URL is empty. ErrOIDCIssuerEmpty = errors.New("oidc issuer url is empty") // ErrOIDCClientIDEmpty indicates that the OIDC client ID is empty. ErrOIDCClientIDEmpty = errors.New("oidc client id is empty") // ErrOIDCClientSecretEmpty indicates that the OIDC client secret is empty. ErrOIDCClientSecretEmpty = errors.New("oidc client secret is empty") )
var ( // ErrSecretKeyEmpty indicates that the secret key is empty. ErrSecretKeyEmpty = errors.New("secret key is empty") // ErrDBLicenseKeyEmpty indicates that the database license key is empty. ErrAssetDirEmpty = errors.New("asset directory cannot be empty") )
var ( // ErrDBDSNEmpty indicates that the database DSN is empty. ErrDBDSNEmpty = errors.New("database DSN is empty") // ErrUnsupportedDB indicates that the database type is unsupported. ErrUnsupportedDB = errors.New("unsupported database type") )
var ( // ErrInvalidLogLevel indicates that the log level is invalid. ErrInvalidLogLevel = errors.New("invalid log level") // ErrInvalidLogMode indicates that the log mode is invalid. ErrInvalidLogMode = errors.New("invalid log mode") // ErrDataDirCreation indicates that the data directory could not be created. ErrDataDirCreation = errors.New("failed to create data directory") // ErrConfigUnmarshal indicates that the configuration could not be unmarshaled. ErrConfigUnmarshal = errors.New("failed to unmarshal configuration") )
var ( // ErrMaxMindLicenseKeyEmpty indicates that the MaxMind license key is empty. ErrMaxMindLicenseKeyEmpty = errors.New("MaxMind license key is required") // ErrMaxMindAutoUpdateIntervalInvalid indicates that the MaxMind auto-update interval is invalid. ErrMaxMindAutoUpdateIntervalInvalid = errors.New("MaxMind auto-update interval must be positive") )
var ( // ErrInvalidPort indicates that the server port is invalid. ErrInvalidPort = errors.New("invalid server port. Port must be between 1 and 65535") // ErrInvalidBaseURL indicates that the server base URL is invalid. ErrInvalidBaseURL = errors.New("invalid server base URL. Base URL must start with http:// or https://") // ErrJWTSecretEmpty indicates that the JWT secret is empty. ErrJWTSecretEmpty = errors.New("jwt secret is required") // ErrAPIListenPortInvalid is an alias for ErrInvalidPort for backwards compatibility. ErrAPIListenPortInvalid = ErrInvalidPort )
Functions ¶
func GenerateConfigFile ¶
GenerateConfigFile generates a config file with default values.
func LoadDefault ¶
func LoadDefault() error
LoadDefault loads the configuration with default settings (no context required).
Types ¶
type Config ¶
type Config struct {
Core CoreConfig `mapstructure:"core"`
Server ServerConfig `mapstructure:"server"`
DB DBConfig `mapstructure:"db"`
MaxMind MaxMindConfig `mapstructure:"maxmind"`
Logger LoggerConfig `mapstructure:"logger"`
OIDC OIDCConfig `mapstructure:"oidc"`
}
Config holds the entire application configuration.
var Current *Config
Current holds the current application configuration.
func (*Config) PostProcess ¶
func (c *Config) PostProcess()
PostProcess performs post-processing on the configuration.
type CoreConfig ¶
type CoreConfig struct {
Environment Environment `mapstructure:"environment"`
SecretKey string `mapstructure:"secret_key"`
DataDir string `mapstructure:"data_dir"`
}
func (*CoreConfig) PostProcess ¶
func (c *CoreConfig) PostProcess()
func (*CoreConfig) Validate ¶
func (c *CoreConfig) Validate() error
type DBConfig ¶
type DBConfig struct {
DSN string `mapstructure:"dsn"`
MaxIdleConn int `mapstructure:"max_idle_conn"`
MaxOpenConn int `mapstructure:"max_open_conn"`
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
}
DBConfig holds database-related configuration.
func (*DBConfig) GetDatabase ¶
GetDatabase returns the database implementation inferred from the DSN scheme.
type Environment ¶
type Environment string
Environment represents the application environment.
const ( // EnvironmentProduction represents the production environment. EnvironmentProduction Environment = "production" // EnvironmentDevelopment represents the development environment. EnvironmentDevelopment Environment = "development" // EnvironmentTesting represents the testing environment. EnvironmentTesting Environment = "testing" )
type LoggerConfig ¶
LoggerConfig holds logger-related configuration.
func (*LoggerConfig) Validate ¶
func (l *LoggerConfig) Validate() error
Validate checks if the logger configuration is valid.
type MaxMindConfig ¶
type MaxMindConfig struct {
LicenseKey string `mapstructure:"license_key"`
AutoUpdate bool `mapstructure:"auto_update"`
AutoUpdateInterval time.Duration `mapstructure:"auto_update_interval"`
}
MaxMindConfig holds MaxMind GeoIP database-related configuration.
func (*MaxMindConfig) Validate ¶
func (m *MaxMindConfig) Validate() error
Validate checks if the MaxMind configuration is valid.
type OIDCConfig ¶
type OIDCConfig struct {
IssuerURL string `mapstructure:"issuer_url"`
ClientID string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
Scopes []string `mapstructure:"scopes"`
}
OIDCConfig holds OIDC authentication configuration.
func (*OIDCConfig) GetRedirectURI ¶
func (o *OIDCConfig) GetRedirectURI(baseURL string) string
GetRedirectURI returns the OIDC redirect URI constructed from BaseURL.
func (*OIDCConfig) Validate ¶
func (o *OIDCConfig) Validate() error
Validate checks if the OIDC configuration is valid.
type ServerConfig ¶
type ServerConfig struct {
ListenAddr string `mapstructure:"listen_addr"`
ListenPort int `mapstructure:"listen_port"`
BaseURL string `mapstructure:"base_url"`
WriteTimeout time.Duration `mapstructure:"write_timeout"`
ReadTimeout time.Duration `mapstructure:"read_timeout"`
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
WaitTimeout time.Duration `mapstructure:"wait_timeout"`
RequestTimeout time.Duration `mapstructure:"request_timeout"`
CertFile string `mapstructure:"cert_file"`
KeyFile string `mapstructure:"key_file"`
}
ServerConfig holds API server-related configuration.
func (*ServerConfig) GetAddr ¶
func (s *ServerConfig) GetAddr() string
GetAddr returns the API server's listen address in "host:port" format.
func (*ServerConfig) PostProcess ¶
func (s *ServerConfig) PostProcess()
PostProcess performs post-processing on the server configuration.
func (*ServerConfig) Validate ¶
func (s *ServerConfig) Validate() error
Validate checks if the server configuration is valid.