Documentation
¶
Index ¶
- func GetIPs() (hostname string, ipList string, ipNetList []net.IP)
- func SetConfigManager(m *Manager)
- type CORSConfig
- type CacheConfig
- type Config
- type DBConnectionConfig
- type DBManagerConfig
- type ErrorTrackingConfig
- type EventBrokerConfig
- type EventBrokerDatabaseConfig
- type EventBrokerNATSConfig
- type EventBrokerRedisConfig
- type EventBrokerRetryPolicyConfig
- type LoggerConfig
- type Manager
- func (m *Manager) ConfigFileUsed() string
- func (m *Manager) Get(key string) interface{}
- func (m *Manager) GetBool(key string) bool
- func (m *Manager) GetConfig() (*Config, error)
- func (m *Manager) GetInt(key string) int
- func (m *Manager) GetString(key string) string
- func (m *Manager) Load() error
- func (m *Manager) SaveConfig(path string) error
- func (m *Manager) Set(key string, value interface{})
- func (m *Manager) SetConfig(cfg *Config) error
- type MemcacheConfig
- type MiddlewareConfig
- type Option
- type PathsConfig
- func (pc PathsConfig) AbsPath(name string) (string, error)
- func (pc PathsConfig) EnsureDir(name string, perm os.FileMode) error
- func (pc PathsConfig) Get(name string) (string, error)
- func (pc PathsConfig) GetOrDefault(name, defaultPath string) string
- func (pc PathsConfig) Has(name string) bool
- func (pc PathsConfig) Join(name string, elem ...string) (string, error)
- func (pc PathsConfig) List() []string
- func (pc *PathsConfig) Set(name, path string)
- type RedisConfig
- type ServerInstanceConfig
- type ServersConfig
- type TracingConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetIPs ¶ added in v1.0.23
GetIPs returns the hostname, a comma-separated list of non-loopback IPs and the same IPs as []net.IP. The lookup is bounded by a short timeout.
func SetConfigManager ¶ added in v1.2.0
func SetConfigManager(m *Manager)
SetConfigManager publishes m as the global manager returned by GetConfigManager. NewManager no longer does this implicitly.
Types ¶
type CORSConfig ¶
type CORSConfig struct {
AllowedOrigins []string `mapstructure:"allowed_origins"`
AllowedMethods []string `mapstructure:"allowed_methods"`
AllowedHeaders []string `mapstructure:"allowed_headers"`
MaxAge int `mapstructure:"max_age"`
}
CORSConfig holds CORS configuration
type CacheConfig ¶
type CacheConfig struct {
Provider string `mapstructure:"provider"` // memory, redis, memcache
Redis RedisConfig `mapstructure:"redis"`
Memcache MemcacheConfig `mapstructure:"memcache"`
}
CacheConfig holds cache provider configuration
type Config ¶
type Config struct {
Servers ServersConfig `mapstructure:"servers"`
Tracing TracingConfig `mapstructure:"tracing"`
Cache CacheConfig `mapstructure:"cache"`
Logger LoggerConfig `mapstructure:"logger"`
ErrorTracking ErrorTrackingConfig `mapstructure:"error_tracking"`
Middleware MiddlewareConfig `mapstructure:"middleware"`
CORS CORSConfig `mapstructure:"cors"`
EventBroker EventBrokerConfig `mapstructure:"event_broker"`
DBManager DBManagerConfig `mapstructure:"dbmanager"`
Paths PathsConfig `mapstructure:"paths"`
Extensions map[string]interface{} `mapstructure:"extensions"`
}
Config represents the complete application configuration
type DBConnectionConfig ¶ added in v1.0.6
type DBConnectionConfig struct {
// Name is the unique name of this connection
Name string `mapstructure:"name"`
// Type is the database type (postgres, sqlite, mssql, mongodb)
Type string `mapstructure:"type"`
// DSN is the complete Data Source Name / connection string
// If provided, this takes precedence over individual connection parameters
DSN string `mapstructure:"dsn"`
// Connection parameters (used if DSN is not provided)
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
User string `mapstructure:"user"`
Password string `mapstructure:"password"`
Database string `mapstructure:"database"`
// PostgreSQL/MSSQL specific
SSLMode string `mapstructure:"sslmode"` // disable, require, verify-ca, verify-full
Schema string `mapstructure:"schema"` // Default schema
// SQLite specific
FilePath string `mapstructure:"filepath"`
// MongoDB specific
AuthSource string `mapstructure:"auth_source"`
ReplicaSet string `mapstructure:"replica_set"`
ReadPreference string `mapstructure:"read_preference"` // primary, secondary, etc.
// Connection pool settings (overrides global defaults)
MaxOpenConns *int `mapstructure:"max_open_conns"`
MaxIdleConns *int `mapstructure:"max_idle_conns"`
ConnMaxLifetime *time.Duration `mapstructure:"conn_max_lifetime"`
ConnMaxIdleTime *time.Duration `mapstructure:"conn_max_idle_time"`
// Timeouts
ConnectTimeout time.Duration `mapstructure:"connect_timeout"`
QueryTimeout time.Duration `mapstructure:"query_timeout"`
// Features
EnableTracing bool `mapstructure:"enable_tracing"`
EnableMetrics bool `mapstructure:"enable_metrics"`
EnableLogging bool `mapstructure:"enable_logging"`
// DefaultORM specifies which ORM to use for the Database() method
// Options: "bun", "gorm", "native"
DefaultORM string `mapstructure:"default_orm"`
// Tags for organization and filtering
Tags map[string]string `mapstructure:"tags"`
}
DBConnectionConfig defines configuration for a single database connection
func (*DBConnectionConfig) PopulateFromDSN ¶ added in v1.0.10
func (cc *DBConnectionConfig) PopulateFromDSN() error
PopulateFromDSN parses a DSN and populates the connection fields
type DBManagerConfig ¶ added in v1.0.6
type DBManagerConfig struct {
// DefaultConnection is the name of the default connection to use
DefaultConnection string `mapstructure:"default_connection"`
// Connections is a map of connection name to connection configuration
Connections map[string]DBConnectionConfig `mapstructure:"connections"`
// Global connection pool defaults
MaxOpenConns int `mapstructure:"max_open_conns"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
ConnMaxLifetime time.Duration `mapstructure:"conn_max_lifetime"`
ConnMaxIdleTime time.Duration `mapstructure:"conn_max_idle_time"`
// Retry policy
RetryAttempts int `mapstructure:"retry_attempts"`
RetryDelay time.Duration `mapstructure:"retry_delay"`
RetryMaxDelay time.Duration `mapstructure:"retry_max_delay"`
// Health checks
HealthCheckInterval time.Duration `mapstructure:"health_check_interval"`
EnableAutoReconnect bool `mapstructure:"enable_auto_reconnect"`
}
DBManagerConfig contains configuration for the database connection manager
func (*DBManagerConfig) ToManagerConfig ¶ added in v1.0.6
func (c *DBManagerConfig) ToManagerConfig() interface{}
ToManagerConfig converts config.DBManagerConfig to dbmanager.ManagerConfig This is used to avoid circular dependencies
func (*DBManagerConfig) Validate ¶ added in v1.0.6
func (c *DBManagerConfig) Validate() error
Validate validates the DBManager configuration
type ErrorTrackingConfig ¶ added in v0.0.98
type ErrorTrackingConfig struct {
Enabled bool `mapstructure:"enabled"`
Provider string `mapstructure:"provider"` // sentry, noop
DSN string `mapstructure:"dsn"` // Sentry DSN
Environment string `mapstructure:"environment"` // e.g., production, staging, development
Release string `mapstructure:"release"` // Application version/release
Debug bool `mapstructure:"debug"` // Enable debug mode
SampleRate float64 `mapstructure:"sample_rate"` // Error sample rate (0.0-1.0)
TracesSampleRate float64 `mapstructure:"traces_sample_rate"` // Traces sample rate (0.0-1.0)
}
ErrorTrackingConfig holds error tracking configuration
type EventBrokerConfig ¶ added in v0.0.107
type EventBrokerConfig struct {
Enabled bool `mapstructure:"enabled"`
Provider string `mapstructure:"provider"` // memory, redis, nats, database
Mode string `mapstructure:"mode"` // sync, async
WorkerCount int `mapstructure:"worker_count"`
BufferSize int `mapstructure:"buffer_size"`
InstanceID string `mapstructure:"instance_id"`
Redis EventBrokerRedisConfig `mapstructure:"redis"`
NATS EventBrokerNATSConfig `mapstructure:"nats"`
Database EventBrokerDatabaseConfig `mapstructure:"database"`
RetryPolicy EventBrokerRetryPolicyConfig `mapstructure:"retry_policy"`
}
EventBrokerConfig contains configuration for the event broker
type EventBrokerDatabaseConfig ¶ added in v0.0.107
type EventBrokerDatabaseConfig struct {
TableName string `mapstructure:"table_name"`
Channel string `mapstructure:"channel"` // PostgreSQL NOTIFY channel name
PollInterval time.Duration `mapstructure:"poll_interval"`
}
EventBrokerDatabaseConfig contains database provider configuration
type EventBrokerNATSConfig ¶ added in v0.0.107
type EventBrokerNATSConfig struct {
URL string `mapstructure:"url"`
StreamName string `mapstructure:"stream_name"`
Subjects []string `mapstructure:"subjects"`
Storage string `mapstructure:"storage"` // file, memory
MaxAge time.Duration `mapstructure:"max_age"`
}
EventBrokerNATSConfig contains NATS-specific configuration
type EventBrokerRedisConfig ¶ added in v0.0.107
type EventBrokerRedisConfig struct {
StreamName string `mapstructure:"stream_name"`
ConsumerGroup string `mapstructure:"consumer_group"`
MaxLen int64 `mapstructure:"max_len"`
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Password string `mapstructure:"password"`
DB int `mapstructure:"db"`
}
EventBrokerRedisConfig contains Redis-specific configuration
type EventBrokerRetryPolicyConfig ¶ added in v0.0.107
type EventBrokerRetryPolicyConfig struct {
MaxRetries int `mapstructure:"max_retries"`
InitialDelay time.Duration `mapstructure:"initial_delay"`
MaxDelay time.Duration `mapstructure:"max_delay"`
BackoffFactor float64 `mapstructure:"backoff_factor"`
}
EventBrokerRetryPolicyConfig contains retry policy configuration
type LoggerConfig ¶
LoggerConfig holds logger configuration
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles configuration loading from multiple sources. viper.Viper is not safe for concurrent use, so every access to it is guarded by mu.
func GetConfigManager ¶ added in v1.0.23
func GetConfigManager() *Manager
GetConfigManager returns a singleton configuration manager instance
func NewManager ¶
func NewManager() *Manager
NewManager creates a new, isolated configuration manager with defaults. It does not replace the global manager; use SetConfigManager for that.
func NewManagerWithOptions ¶
NewManagerWithOptions creates a new configuration manager with custom options
func (*Manager) ConfigFileUsed ¶ added in v1.2.0
ConfigFileUsed returns the config file that was read by Load, or "" if none was found (i.e. the manager is running on defaults and environment variables only).
func (*Manager) Load ¶
Load attempts to load configuration from file and environment. A missing config file is not an error (defaults and env vars are used); check ConfigFileUsed after Load to see whether a file was actually read.
func (*Manager) SaveConfig ¶ added in v1.0.8
SaveConfig writes the current configuration to the specified path. The file contains the entire merged configuration, including secrets (database/redis passwords, error-tracking DSN), so it is written with mode 0600. Prefer supplying secrets via RESOLVESPEC_* environment variables.
type MemcacheConfig ¶
type MemcacheConfig struct {
Servers []string `mapstructure:"servers"`
MaxIdleConns int `mapstructure:"max_idle_conns"`
Timeout time.Duration `mapstructure:"timeout"`
}
MemcacheConfig holds Memcache-specific configuration
type MiddlewareConfig ¶
type MiddlewareConfig struct {
RateLimitRPS float64 `mapstructure:"rate_limit_rps"`
RateLimitBurst int `mapstructure:"rate_limit_burst"`
MaxRequestSize int64 `mapstructure:"max_request_size"`
}
MiddlewareConfig holds middleware configuration
type Option ¶
type Option func(*Manager)
Option is a functional option for configuring the Manager
func WithConfigFile ¶
WithConfigFile sets a specific config file path
func WithConfigName ¶
WithConfigName sets the config file name (without extension)
func WithConfigPath ¶
WithConfigPath adds a path to search for config files
func WithEnvPrefix ¶
WithEnvPrefix sets the environment variable prefix
type PathsConfig ¶ added in v1.0.11
PathsConfig contains configuration for named file system paths This is a map of path name to file system path Example: "data_dir": "/var/lib/myapp/data"
func (PathsConfig) AbsPath ¶ added in v1.0.11
func (pc PathsConfig) AbsPath(name string) (string, error)
AbsPath returns the absolute path for a named path
func (PathsConfig) EnsureDir ¶ added in v1.0.11
func (pc PathsConfig) EnsureDir(name string, perm os.FileMode) error
EnsureDir ensures a directory exists at the specified path name Creates the directory if it doesn't exist with the given permissions
func (PathsConfig) Get ¶ added in v1.0.11
func (pc PathsConfig) Get(name string) (string, error)
Get retrieves a path by name
func (PathsConfig) GetOrDefault ¶ added in v1.0.11
func (pc PathsConfig) GetOrDefault(name, defaultPath string) string
GetOrDefault retrieves a path by name, returning defaultPath if not found
func (PathsConfig) Has ¶ added in v1.0.11
func (pc PathsConfig) Has(name string) bool
Has checks if a path exists by name
func (PathsConfig) Join ¶ added in v1.0.11
func (pc PathsConfig) Join(name string, elem ...string) (string, error)
Join joins path segments with a named base path. It returns an error if the result would escape the base path.
func (PathsConfig) List ¶ added in v1.0.11
func (pc PathsConfig) List() []string
List returns all configured path names
func (*PathsConfig) Set ¶ added in v1.0.11
func (pc *PathsConfig) Set(name, path string)
Set sets a path by name. It takes a pointer so a nil map can be allocated. PathsConfig is not safe for concurrent mutation; populate it before sharing.
type RedisConfig ¶
type RedisConfig struct {
Host string `mapstructure:"host"`
Port int `mapstructure:"port"`
Password string `mapstructure:"password"`
DB int `mapstructure:"db"`
}
RedisConfig holds Redis-specific configuration
type ServerInstanceConfig ¶ added in v1.0.11
type ServerInstanceConfig struct {
// Name is the unique name of this server instance
Name string `mapstructure:"name"`
// Host is the host to bind to (e.g., "localhost", "0.0.0.0", "")
Host string `mapstructure:"host"`
// Port is the port number to listen on
Port int `mapstructure:"port"`
// Description is a human-readable description of this server
Description string `mapstructure:"description"`
// GZIP enables GZIP compression middleware
GZIP bool `mapstructure:"gzip"`
// HTTP2 enables HTTP/2 with the Extended CONNECT protocol (RFC 8441) for WebSocket support.
// Requires TLS; pair with SSLCert/SSLKey, SelfSignedSSL, or AutoTLS.
HTTP2 bool `mapstructure:"http2"`
// TLS/HTTPS configuration options (mutually exclusive)
// Option 1: Provide certificate and key files directly
SSLCert string `mapstructure:"ssl_cert"`
SSLKey string `mapstructure:"ssl_key"`
// Option 2: Use self-signed certificate (for development/testing)
SelfSignedSSL bool `mapstructure:"self_signed_ssl"`
// Option 3: Use Let's Encrypt / AutoTLS
AutoTLS bool `mapstructure:"auto_tls"`
AutoTLSDomains []string `mapstructure:"auto_tls_domains"`
AutoTLSCacheDir string `mapstructure:"auto_tls_cache_dir"`
AutoTLSEmail string `mapstructure:"auto_tls_email"`
// Timeout configurations (overrides global defaults)
ShutdownTimeout *time.Duration `mapstructure:"shutdown_timeout"`
DrainTimeout *time.Duration `mapstructure:"drain_timeout"`
ReadTimeout *time.Duration `mapstructure:"read_timeout"`
WriteTimeout *time.Duration `mapstructure:"write_timeout"`
IdleTimeout *time.Duration `mapstructure:"idle_timeout"`
// Tags for organization and filtering
Tags map[string]string `mapstructure:"tags"`
// ExternalURLs are additional URLs that this server instance is accessible from (for CORS) for proxy setups
ExternalURLs []string `mapstructure:"external_urls"`
}
ServerInstanceConfig defines configuration for a single server instance
func (*ServerInstanceConfig) ApplyGlobalDefaults ¶ added in v1.0.11
func (sic *ServerInstanceConfig) ApplyGlobalDefaults(globals ServersConfig)
ApplyGlobalDefaults applies global server defaults to this instance Called for instances that don't specify their own timeout values
func (*ServerInstanceConfig) Validate ¶ added in v1.0.11
func (sic *ServerInstanceConfig) Validate() error
Validate validates the ServerInstanceConfig
type ServersConfig ¶ added in v1.0.11
type ServersConfig struct {
// DefaultServer is the name of the default server to use
DefaultServer string `mapstructure:"default_server"`
// Instances is a map of server name to server configuration
Instances map[string]ServerInstanceConfig `mapstructure:"instances"`
// Global timeout defaults (can be overridden per instance)
ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout"`
DrainTimeout time.Duration `mapstructure:"drain_timeout"`
ReadTimeout time.Duration `mapstructure:"read_timeout"`
WriteTimeout time.Duration `mapstructure:"write_timeout"`
IdleTimeout time.Duration `mapstructure:"idle_timeout"`
}
ServersConfig contains configuration for the server manager
func (*ServersConfig) GetDefault ¶ added in v1.0.11
func (sc *ServersConfig) GetDefault() (*ServerInstanceConfig, error)
GetDefault returns the default server instance configuration. The returned pointer refers to a copy: mutating it does not modify sc.Instances.
func (*ServersConfig) Validate ¶ added in v1.0.11
func (sc *ServersConfig) Validate() error
Validate validates the ServersConfig
type TracingConfig ¶
type TracingConfig struct {
Enabled bool `mapstructure:"enabled"`
ServiceName string `mapstructure:"service_name"`
ServiceVersion string `mapstructure:"service_version"`
Endpoint string `mapstructure:"endpoint"`
// Insecure exports traces over plaintext gRPC (default false: TLS).
Insecure bool `mapstructure:"insecure"`
// SampleRate is the fraction of root traces sampled; 0 selects the default (0.1).
SampleRate float64 `mapstructure:"sample_rate"`
// Headers are sent with every OTLP export request (e.g. auth tokens).
Headers map[string]string `mapstructure:"headers"`
}
TracingConfig holds OpenTelemetry tracing configuration