Documentation
¶
Index ¶
- Constants
- func IsDatabaseConfigured(cfg *DatabaseConfig) bool
- func Validate(cfg *Config) error
- type AppConfig
- type AuthConfig
- type BrokerConfig
- type CacheConfig
- type CleanupConfig
- type ConcernConfig
- type Config
- func (c *Config) All() map[string]any
- func (c *Config) Custom() map[string]any
- func (c *Config) Exists(key string) bool
- func (c *Config) GetBool(key string, defaultVal ...bool) bool
- func (c *Config) GetFloat64(key string, defaultVal ...float64) float64
- func (c *Config) GetInt(key string, defaultVal ...int) int
- func (c *Config) GetInt64(key string, defaultVal ...int64) int64
- func (c *Config) GetRequiredBool(key string) (bool, error)
- func (c *Config) GetRequiredFloat64(key string) (float64, error)
- func (c *Config) GetRequiredInt(key string) (int, error)
- func (c *Config) GetRequiredInt64(key string) (int64, error)
- func (c *Config) GetRequiredString(key string) (string, error)
- func (c *Config) GetString(key string, defaultVal ...string) string
- func (c *Config) InjectInto(target any) error
- func (c *Config) Unmarshal(key string, out any) error
- type DatabaseConfig
- type IDValidationConfig
- type IPPreGuardConfig
- type LifetimeConfig
- type LimitsConfig
- type LogConfig
- type MessagingConfig
- type MongoConfig
- type MultitenantConfig
- type OracleConfig
- type OutputConfig
- type PathConfig
- type PoolConfig
- type PoolIdleConfig
- type PoolMaxConfig
- type QueryConfig
- type QueryLogConfig
- type RateConfig
- type ReplicaConfig
- type ResolverConfig
- type RoutingConfig
- type ServerConfig
- type ServiceConfig
- type SlowQueryConfig
- type TLSConfig
- type TimeoutConfig
Constants ¶
const ( PostgreSQL = "postgresql" Oracle = "oracle" MongoDB = "mongodb" )
Database type constants
const ( EnvDevelopment = "development" EnvStaging = "staging" EnvProduction = "production" )
Environment constants
Variables ¶
This section is empty.
Functions ¶
func IsDatabaseConfigured ¶ added in v0.4.1
func IsDatabaseConfigured(cfg *DatabaseConfig) bool
IsDatabaseConfigured determines if database is intentionally configured. This mirrors the logic used in app.isDatabaseEnabled() for consistency.
Types ¶
type AppConfig ¶
type AppConfig struct {
Name string `koanf:"name"`
Version string `koanf:"version"`
Env string `koanf:"env"`
Debug bool `koanf:"debug"`
Namespace string `koanf:"namespace"`
Rate RateConfig `koanf:"rate"`
}
AppConfig holds general application settings.
type AuthConfig ¶ added in v0.7.1
type AuthConfig struct {
Source string `koanf:"source"`
}
AuthConfig holds MongoDB authentication source settings.
type BrokerConfig ¶ added in v0.7.1
BrokerConfig holds message broker connection settings.
type CacheConfig ¶ added in v0.18.0
CacheConfig holds caching settings for tenant configurations.
type CleanupConfig ¶
CleanupConfig holds connection cleanup settings.
type ConcernConfig ¶ added in v0.7.1
type ConcernConfig struct {
Write string `koanf:"write"`
}
ConcernConfig holds MongoDB write concern settings.
type Config ¶
type Config struct {
App AppConfig `koanf:"app"`
Server ServerConfig `koanf:"server"`
Database DatabaseConfig `koanf:"database"`
Log LogConfig `koanf:"log"`
Messaging MessagingConfig `koanf:"messaging"`
Multitenant MultitenantConfig `koanf:"multitenant"`
// contains filtered or unexported fields
}
Config represents the overall application configuration structure. It includes sections for application settings, server parameters, database connection details, logging preferences, and messaging options. The embedded koanf.Koanf instance allows for flexible access to additional custom configurations not explicitly defined in the struct.
func Load ¶
Load loads configuration from multiple sources with priority: 1. Environment variables (highest priority) 2. YAML configuration files 3. Default values (lowest priority)
func (*Config) GetBool ¶ added in v0.4.0
GetBool retrieves a bool value from the configuration or the provided default.
func (*Config) GetFloat64 ¶ added in v0.4.0
GetFloat64 retrieves a float64 value from the configuration or the provided default.
func (*Config) GetInt ¶ added in v0.4.0
GetInt retrieves an int value from the configuration or the provided default.
func (*Config) GetInt64 ¶ added in v0.4.0
GetInt64 retrieves an int64 value from the configuration or the provided default.
func (*Config) GetRequiredBool ¶ added in v0.4.0
GetRequiredBool retrieves a required bool value from the configuration.
func (*Config) GetRequiredFloat64 ¶ added in v0.4.0
GetRequiredFloat64 retrieves a required float64 value from the configuration.
func (*Config) GetRequiredInt ¶ added in v0.4.0
GetRequiredInt retrieves a required int value from the configuration.
func (*Config) GetRequiredInt64 ¶ added in v0.4.0
GetRequiredInt64 retrieves a required int64 value from the configuration.
func (*Config) GetRequiredString ¶ added in v0.4.0
GetRequiredString retrieves a required string value from the configuration.
func (*Config) GetString ¶ added in v0.4.0
GetString retrieves a string value from the configuration or the provided default.
func (*Config) InjectInto ¶ added in v0.6.0
InjectInto populates a struct with configuration values based on struct tags. It supports the following struct tags:
- `config:"key.path"` - specifies the configuration key to use
- `required:"true"` - marks the field as required (default: false)
- `default:"value"` - provides a default value if the config key is missing
Supported field types: string, int, int64, float64, bool, time.Duration
type DatabaseConfig ¶
type DatabaseConfig struct {
Type string `koanf:"type"`
Host string `koanf:"host"`
Port int `koanf:"port"`
Database string `koanf:"database"`
Username string `koanf:"username"`
Password string `koanf:"password"`
ConnectionString string `koanf:"connectionstring"`
Pool PoolConfig `koanf:"pool"`
Query QueryConfig `koanf:"query"`
TLS TLSConfig `koanf:"tls"`
Oracle OracleConfig `koanf:"oracle"`
Mongo MongoConfig `koanf:"mongo"`
}
DatabaseConfig holds database connection settings.
type IDValidationConfig ¶
type IDValidationConfig struct {
Pattern string `koanf:"pattern"` // default: ^[a-z0-9-]{1,64}$
// contains filtered or unexported fields
}
IDValidationConfig holds tenant ID validation settings.
func (*IDValidationConfig) GetPattern ¶
func (c *IDValidationConfig) GetPattern() string
GetPattern returns the current pattern string safely.
func (*IDValidationConfig) GetRegex ¶
func (c *IDValidationConfig) GetRegex() *regexp.Regexp
GetRegex returns the compiled regex for tenant ID validation.
func (*IDValidationConfig) SetRegex ¶
func (c *IDValidationConfig) SetRegex(pattern string) error
SetRegex compiles and sets the regex pattern.
type IPPreGuardConfig ¶ added in v0.9.0
type IPPreGuardConfig struct {
Enabled bool `koanf:"enabled"` // enable IP pre-guard rate limiting
Threshold int `koanf:"threshold"` // requests per second limit per IP
}
IPPreGuardConfig holds IP pre-guard rate limiting settings.
type LifetimeConfig ¶ added in v0.7.1
LifetimeConfig holds maximum lifetime settings for connections.
type LimitsConfig ¶ added in v0.9.0
type LimitsConfig struct {
Tenants int `koanf:"tenants"` // default: 100
Cleanup CleanupConfig `koanf:"cleanup"`
}
LimitsConfig holds resource limits for multi-tenant operation.
type LogConfig ¶
type LogConfig struct {
Level string `koanf:"level"`
Pretty bool `koanf:"pretty"`
Output OutputConfig `koanf:"output"`
}
LogConfig holds logging settings.
type MessagingConfig ¶
type MessagingConfig struct {
Broker BrokerConfig `koanf:"broker"`
Routing RoutingConfig `koanf:"routing"`
Headers map[string]string `koanf:"headers"`
}
MessagingConfig holds messaging/broker settings.
type MongoConfig ¶ added in v0.7.1
type MongoConfig struct {
Replica ReplicaConfig `koanf:"replica"`
Auth AuthConfig `koanf:"auth"`
Concern ConcernConfig `koanf:"concern"`
}
MongoConfig holds MongoDB-specific database settings.
type MultitenantConfig ¶ added in v0.9.0
type MultitenantConfig struct {
Enabled bool `koanf:"enabled"`
Resolver ResolverConfig `koanf:"resolver"`
Cache CacheConfig `koanf:"cache"`
Limits LimitsConfig `koanf:"limits"`
Validation IDValidationConfig `koanf:"validation"`
}
MultitenantConfig holds multi-tenant specific settings.
type OracleConfig ¶ added in v0.7.1
type OracleConfig struct {
Service ServiceConfig `koanf:"service"`
}
OracleConfig holds Oracle-specific database settings.
type OutputConfig ¶ added in v0.7.1
OutputConfig holds log output settings.
type PathConfig ¶ added in v0.7.1
type PathConfig struct {
Base string `koanf:"base"`
Health string `koanf:"health"`
Ready string `koanf:"ready"`
}
PathConfig holds URL path settings for the server.
type PoolConfig ¶ added in v0.7.1
type PoolConfig struct {
Max PoolMaxConfig `koanf:"max"`
Idle PoolIdleConfig `koanf:"idle"`
Lifetime LifetimeConfig `koanf:"lifetime"`
}
PoolConfig holds connection pool settings.
type PoolIdleConfig ¶ added in v0.7.1
type PoolIdleConfig struct {
Connections int32 `koanf:"connections"`
Time time.Duration `koanf:"time"`
}
PoolIdleConfig holds idle connections settings.
type PoolMaxConfig ¶ added in v0.7.1
type PoolMaxConfig struct {
Connections int32 `koanf:"connections"`
}
PoolMaxConfig holds maximum connections settings.
type QueryConfig ¶ added in v0.7.1
type QueryConfig struct {
Slow SlowQueryConfig `koanf:"slow"`
Log QueryLogConfig `koanf:"log"`
}
QueryConfig holds settings related to query logging and slow query detection.
type QueryLogConfig ¶ added in v0.7.1
QueryLogConfig holds settings for query logging.
type RateConfig ¶ added in v0.7.0
type RateConfig struct {
Limit int `koanf:"limit"`
Burst int `koanf:"burst"`
IPPreGuard IPPreGuardConfig `koanf:"ippreguard"`
}
RateConfig holds rate limiting settings.
type ReplicaConfig ¶ added in v0.7.1
ReplicaConfig holds MongoDB replica set and read preference settings.
type ResolverConfig ¶ added in v0.9.0
type ResolverConfig struct {
Type string `koanf:"type"` // header, subdomain, composite
Header string `koanf:"header"` // default: X-Tenant-ID
Domain string `koanf:"domain"` // e.g., api.example.com or .api.example.com (leading dot optional)
Proxies bool `koanf:"proxies"` // trust X-Forwarded-Host
}
ResolverConfig holds tenant resolution strategy settings.
type RoutingConfig ¶ added in v0.7.1
RoutingConfig holds message routing settings.
type ServerConfig ¶
type ServerConfig struct {
Host string `koanf:"host"`
Port int `koanf:"port"`
Timeout TimeoutConfig `koanf:"timeout"`
Path PathConfig `koanf:"path"`
}
ServerConfig holds HTTP server settings.
type ServiceConfig ¶ added in v0.7.0
ServiceConfig holds Oracle service connection settings.
type SlowQueryConfig ¶ added in v0.7.1
type SlowQueryConfig struct {
Threshold time.Duration `koanf:"threshold"`
Enabled bool `koanf:"enabled"`
}
SlowQueryConfig holds settings for slow query detection.
type TLSConfig ¶ added in v0.7.1
type TLSConfig struct {
Mode string `koanf:"mode"`
CertFile string `koanf:"cert"`
KeyFile string `koanf:"key"`
CAFile string `koanf:"ca"`
}
TLSConfig holds TLS/SSL settings for database connections.
type TimeoutConfig ¶ added in v0.7.1
type TimeoutConfig struct {
Read time.Duration `koanf:"read"`
Write time.Duration `koanf:"write"`
Idle time.Duration `koanf:"idle"`
Middleware time.Duration `koanf:"middleware"`
Shutdown time.Duration `koanf:"shutdown"`
}
TimeoutConfig holds various timeout durations for the server.