Documentation
¶
Overview ¶
Package config provides configuration management for XxSql.
Package config provides configuration management for XxSql.
Index ¶
- func GenerateExampleConfig() ([]byte, error)
- func Save(cfg *Config, path string) error
- func SaveConfig(cfg *Config, path string) error
- type AuthConfig
- type BackupConfig
- type Config
- type ConnectionConfig
- type Loader
- type LogConfig
- type NetworkConfig
- type RecoveryConfig
- type SafetyConfig
- type SecurityConfig
- type ServerConfig
- type StorageConfig
- type WorkerConfig
- type WorkerPoolConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateExampleConfig ¶
GenerateExampleConfig generates an example configuration file.
func SaveConfig ¶
SaveConfig saves the configuration to a file.
Types ¶
type AuthConfig ¶
type AuthConfig struct {
Enabled bool `json:"enabled"` // Enable authentication
AdminPassword string `json:"admin_password"` // Admin password hash
AdminUser string `json:"admin_user"` // Admin username
SessionTimeouSec int `json:"session_timeout_sec"` // Session timeout in seconds
}
AuthConfig contains authentication configuration.
type BackupConfig ¶
type BackupConfig struct {
AutoIntervalHours int `json:"auto_interval_hours"` // Auto backup interval in hours
KeepCount int `json:"keep_count"` // Number of backups to keep
BackupDir string `json:"backup_dir"` // Backup directory path
}
BackupConfig contains backup configuration.
type Config ¶
type Config struct {
Server ServerConfig `json:"server"`
Network NetworkConfig `json:"network"`
Storage StorageConfig `json:"storage"`
Worker WorkerConfig `json:"worker"`
Log LogConfig `json:"log"`
Auth AuthConfig `json:"auth"`
Security SecurityConfig `json:"security"`
Backup BackupConfig `json:"backup"`
Recovery RecoveryConfig `json:"recovery"`
Safety SafetyConfig `json:"safety"`
Connection ConnectionConfig `json:"connection"`
WorkerPool WorkerPoolConfig `json:"worker_pool"`
}
Config is the root configuration structure for XxSql.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with all default values applied.
type ConnectionConfig ¶
type ConnectionConfig struct {
MaxConnections int `json:"max_connections"` // Maximum total connections
WaitTimeout int `json:"wait_timeout"` // Connection wait timeout in seconds
Strategy string `json:"strategy"` // Connection strategy: fifo, lifo, random
DegradeThreshold int `json:"degrade_threshold"` // Threshold for degraded mode
IdleTimeout int `json:"idle_timeout"` // Idle connection timeout in seconds
}
ConnectionConfig contains connection management configuration.
type Loader ¶
type Loader struct {
// contains filtered or unexported fields
}
Loader handles configuration loading with priority.
type LogConfig ¶
type LogConfig struct {
Level string `json:"level"` // Log level: DEBUG, INFO, WARN, ERROR
File string `json:"file"` // Log file path (empty for stdout)
MaxSizeMB int `json:"max_size_mb"` // Max log file size before rotation
MaxBackups int `json:"max_backups"` // Max number of old log files to keep
MaxAgeDays int `json:"max_age_days"` // Max days to keep old log files
Compress bool `json:"compress"` // Whether to compress rotated logs
}
LogConfig contains logging configuration.
type NetworkConfig ¶
type NetworkConfig struct {
PrivatePort int `json:"private_port"` // Private protocol port (default: 9527)
MySQLPort int `json:"mysql_port"` // MySQL compatible port (default: 3306)
HTTPPort int `json:"http_port"` // HTTP API port (default: 8080)
Bind string `json:"bind"` // Default bind address (default: "0.0.0.0")
PrivateBind string `json:"private_bind"` // Bind address for private port (overrides Bind)
MySQLBind string `json:"mysql_bind"` // Bind address for MySQL port (overrides Bind)
HTTPBind string `json:"http_bind"` // Bind address for HTTP port (overrides Bind)
PrivateEnabled *bool `json:"private_enabled"` // Enable private protocol server (default: true)
MySQLEnabled *bool `json:"mysql_enabled"` // Enable MySQL protocol server (default: true)
HTTPEnabled *bool `json:"http_enabled"` // Enable HTTP API server (default: true)
}
NetworkConfig contains network-related configuration.
func (*NetworkConfig) GetHTTPBind ¶ added in v0.0.5
func (n *NetworkConfig) GetHTTPBind() string
GetHTTPBind returns the bind address for HTTP port. Falls back to Bind if HTTPBind is not set.
func (*NetworkConfig) GetMySQLBind ¶ added in v0.0.5
func (n *NetworkConfig) GetMySQLBind() string
GetMySQLBind returns the bind address for MySQL port. Falls back to Bind if MySQLBind is not set.
func (*NetworkConfig) GetPrivateBind ¶ added in v0.0.5
func (n *NetworkConfig) GetPrivateBind() string
GetPrivateBind returns the bind address for private port. Falls back to Bind if PrivateBind is not set.
func (*NetworkConfig) IsHTTPEnabled ¶ added in v0.0.5
func (n *NetworkConfig) IsHTTPEnabled() bool
IsHTTPEnabled returns whether HTTP API server is enabled.
func (*NetworkConfig) IsMySQLEnabled ¶ added in v0.0.5
func (n *NetworkConfig) IsMySQLEnabled() bool
IsMySQLEnabled returns whether MySQL protocol server is enabled.
func (*NetworkConfig) IsPrivateEnabled ¶ added in v0.0.5
func (n *NetworkConfig) IsPrivateEnabled() bool
IsPrivateEnabled returns whether private protocol server is enabled.
type RecoveryConfig ¶
type RecoveryConfig struct {
WALSyncIntervalMs int `json:"wal_sync_interval_ms"` // WAL sync interval in ms
CheckpointIntervalSec int `json:"checkpoint_interval_sec"` // Checkpoint interval in seconds
CheckpointPages int `json:"checkpoint_pages"` // Pages threshold for checkpoint
WALRetentionSec int `json:"wal_retention_sec"` // WAL retention time in seconds
}
RecoveryConfig contains recovery configuration.
type SafetyConfig ¶
type SafetyConfig struct {
EnableChecksum bool `json:"enable_checksum"` // Enable data checksums
MaxRecoveryAttempts int `json:"max_recovery_attempts"` // Max recovery attempts
}
SafetyConfig contains safety configuration.
type SecurityConfig ¶
type SecurityConfig struct {
// Audit logging
AuditEnabled bool `json:"audit_enabled"`
AuditFile string `json:"audit_file"`
AuditMaxSizeMB int `json:"audit_max_size_mb"`
AuditMaxBackups int `json:"audit_max_backups"`
// Rate limiting
RateLimitEnabled bool `json:"rate_limit_enabled"`
RateLimitMaxAttempts int `json:"rate_limit_max_attempts"`
RateLimitWindowMin int `json:"rate_limit_window_min"`
RateLimitBlockMin int `json:"rate_limit_block_min"`
// Password policy
PasswordMinLength int `json:"password_min_length"`
PasswordRequireUpper bool `json:"password_require_upper"`
PasswordRequireLower bool `json:"password_require_lower"`
PasswordRequireDigit bool `json:"password_require_digit"`
PasswordRequireSpecial bool `json:"password_require_special"`
PasswordExpireDays int `json:"password_expire_days"`
PasswordHistoryCount int `json:"password_history_count"`
// TLS
TLSEnabled bool `json:"tls_enabled"`
TLSMode string `json:"tls_mode"` // disabled, optional, required, verify_ca
TLSCertFile string `json:"tls_cert_file"`
TLSKeyFile string `json:"tls_key_file"`
TLSCAFile string `json:"tls_ca_file"`
// IP Access
IPAccessMode string `json:"ip_access_mode"` // allow_all, whitelist, blacklist
IPWhitelist []string `json:"ip_whitelist"`
IPBlacklist []string `json:"ip_blacklist"`
}
SecurityConfig contains security configuration.
type ServerConfig ¶
type ServerConfig struct {
Name string `json:"name"` // Server instance name
DataDir string `json:"data_dir"` // Data directory path
}
ServerConfig contains server-level configuration.
type StorageConfig ¶
type StorageConfig struct {
PageSize int `json:"page_size"` // Page size in bytes (default: 4096)
BufferPoolSize int `json:"buffer_pool_size"` // Number of buffer pool pages (default: 1000)
WALMaxSizeMB int `json:"wal_max_size_mb"` // Maximum WAL size in MB
WALSyncInterval int `json:"wal_sync_interval"` // WAL sync interval in milliseconds
CheckpointPages int `json:"checkpoint_pages"` // Pages threshold for checkpoint
CheckpointIntSec int `json:"checkpoint_int_sec"` // Checkpoint interval in seconds
}
StorageConfig contains storage engine configuration.
type WorkerConfig ¶
type WorkerConfig struct {
PoolSize int `json:"pool_size"` // Worker pool size (default: 32)
MaxConnection int `json:"max_connection"` // Max connections per worker (default: 200)
}
WorkerConfig contains worker configuration (deprecated, use WorkerPoolConfig).
type WorkerPoolConfig ¶
type WorkerPoolConfig struct {
WorkerCount int `json:"worker_count"` // Number of workers
TaskQueueSize int `json:"task_queue_size"` // Task queue size per worker
TaskTimeout time.Duration `json:"task_timeout"` // Task execution timeout
Strategy string `json:"strategy"` // Load balancing strategy
}
WorkerPoolConfig contains worker pool configuration.