Help us shape the future of Go! Take the 2026 Go Developer Survey

config

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultYAML

func DefaultYAML() []byte

DefaultYAML returns the documented default configuration file.

func ExpandEnv

func ExpandEnv(s string) string

ExpandEnv replaces ${VAR} and ${VAR:-default}. Unlike os.ExpandEnv it leaves bare $VAR alone, so values such as passwords containing '$' are not mangled.

func GenerateDefaultConfig

func GenerateDefaultConfig(filename string, force bool) error

GenerateDefaultConfig writes the default configuration to filename. It refuses to overwrite an existing file unless force is set.

func ParseMemorySize

func ParseMemorySize(size string) (int64, error)

ParseMemorySize parses sizes such as "512MB", "1.5GB", "64kb", "100" or "0". Units are binary (1KB = 1024 bytes). An empty string means 0.

Types

type AuthConfig

type AuthConfig struct {
	Enabled bool     `yaml:"enabled"`
	Method  string   `yaml:"method"`
	Tokens  []string `yaml:"tokens"`
}

type CacheConfig

type CacheConfig struct {
	MaxMemory         string        `yaml:"max_memory"`
	MaxKeys           int           `yaml:"max_keys"`
	DefaultTTL        time.Duration `yaml:"default_ttl"`
	MaxTTL            time.Duration `yaml:"max_ttl"`
	CleanupInterval   time.Duration `yaml:"cleanup_interval"`
	EvictionPolicy    string        `yaml:"eviction_policy"`
	EvictionThreshold float64       `yaml:"eviction_threshold"`
}

type ClusterConfig

type ClusterConfig struct {
	Enabled     bool              `yaml:"enabled"`
	NodeID      string            `yaml:"node_id"`
	Replication ReplicationConfig `yaml:"replication"`
	Discovery   DiscoveryConfig   `yaml:"discovery"`
}

type Config

type Config struct {
	Server      ServerConfig      `yaml:"server"`
	Cache       CacheConfig       `yaml:"cache"`
	Persistence PersistenceConfig `yaml:"persistence"`
	Cluster     ClusterConfig     `yaml:"cluster"`
	Security    SecurityConfig    `yaml:"security"`
	Logging     LoggingConfig     `yaml:"logging"`
	Monitoring  MonitoringConfig  `yaml:"monitoring"`
	Performance PerformanceConfig `yaml:"performance"`
	Features    FeaturesConfig    `yaml:"features"`
}
var GlobalConfig *Config

func Default

func Default() *Config

Default returns the built-in configuration used for any setting missing from the config file.

func LoadConfig

func LoadConfig(filename string) (*Config, error)

LoadConfig reads filename over the defaults. A missing file yields the defaults. ${VAR} and ${VAR:-default} references are expanded from the environment before parsing, so secrets can be injected without editing the file.

func (*Config) AuthTokens

func (c *Config) AuthTokens() []string

AuthTokens returns the configured tokens, ignoring empty entries (which appear when a ${VAR} reference is unset).

func (*Config) GetRESPAddress

func (c *Config) GetRESPAddress() string

func (*Config) GetRESTAddress

func (c *Config) GetRESTAddress() string

func (*Config) GetTCPAddress

func (c *Config) GetTCPAddress() string

func (*Config) IsFeatureEnabled

func (c *Config) IsFeatureEnabled(feature string) bool

func (*Config) RESTEnabled

func (c *Config) RESTEnabled() bool

RESTEnabled reports whether the HTTP API runs.

func (*Config) TCPEnabled

func (c *Config) TCPEnabled() bool

TCPEnabled reports whether the TCP (text + RESP) listener runs.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for errors.

type ConnectionPoolConfig

type ConnectionPoolConfig struct {
	MaxIdle     int           `yaml:"max_idle"`
	MaxActive   int           `yaml:"max_active"`
	IdleTimeout time.Duration `yaml:"idle_timeout"`
}

type DiscoveryConfig

type DiscoveryConfig struct {
	Method    string   `yaml:"method"`
	Endpoints []string `yaml:"endpoints"`
}

type FeaturesConfig

type FeaturesConfig struct {
	LuaScripting bool          `yaml:"lua_scripting"`
	LuaTimeout   time.Duration `yaml:"lua_timeout"`
	PubSub       bool          `yaml:"pub_sub"`
	ComplexTypes bool          `yaml:"complex_types"`
	Transactions bool          `yaml:"transactions"`
	GeoCommands  bool          `yaml:"geo_commands"`
	Streams      bool          `yaml:"streams"`
}

type HealthConfig

type HealthConfig struct {
	Enabled  bool   `yaml:"enabled"`
	Endpoint string `yaml:"endpoint"`
}

type LoggingConfig

type LoggingConfig struct {
	Level      string `yaml:"level"`
	Format     string `yaml:"format"`
	File       string `yaml:"file"`
	MaxSize    string `yaml:"max_size"`
	MaxBackups int    `yaml:"max_backups"`
	Compress   bool   `yaml:"compress"`
}

type MetricsConfig

type MetricsConfig struct {
	Enabled  bool          `yaml:"enabled"`
	Endpoint string        `yaml:"endpoint"`
	Interval time.Duration `yaml:"interval"`
}

type MonitoringConfig

type MonitoringConfig struct {
	Metrics   MetricsConfig   `yaml:"metrics"`
	Health    HealthConfig    `yaml:"health"`
	Profiling ProfilingConfig `yaml:"profiling"`
}

type PerformanceConfig

type PerformanceConfig struct {
	MaxGoroutines   int                  `yaml:"max_goroutines"`
	ReadBufferSize  string               `yaml:"read_buffer_size"`
	WriteBufferSize string               `yaml:"write_buffer_size"`
	GCPercent       int                  `yaml:"gc_percent"`
	ConnectionPool  ConnectionPoolConfig `yaml:"connection_pool"`
}

type PersistenceConfig

type PersistenceConfig struct {
	Enabled     bool           `yaml:"enabled"`
	File        string         `yaml:"file"`
	Interval    time.Duration  `yaml:"interval"`
	Compression bool           `yaml:"compression"`
	BackupCount int            `yaml:"backup_count"`
	Snapshot    SnapshotConfig `yaml:"snapshot"`

	// Cleanup starts only when the total number of backup files
	// exceeds this value.
	// Old backups are deleted until BackupCount files remain.
	CleanupWhenExceeds int `yaml:"cleanup_when_exceeds"`
}

type ProfilingConfig

type ProfilingConfig struct {
	Enabled  bool   `yaml:"enabled"`
	Endpoint string `yaml:"endpoint"`
}

type RESPConfig

type RESPConfig struct {
	Enabled *bool  `yaml:"enabled"`
	Host    string `yaml:"host"`
	Port    int    `yaml:"port"`
}

RESPConfig is the dedicated Redis protocol listener (redis-cli, go-redis, ioredis, redis-py...). The TCP listener also understands RESP; this one replies to inline commands in RESP as well, exactly like Redis.

func (RESPConfig) IsEnabled

func (r RESPConfig) IsEnabled() bool

IsEnabled reports whether the RESP listener should run (default true).

type RESTConfig

type RESTConfig struct {
	Host           string        `yaml:"host"`
	Port           int           `yaml:"port"`
	CORSEnabled    bool          `yaml:"cors_enabled"`
	CORSOrigins    []string      `yaml:"cors_origins"`
	RequestTimeout time.Duration `yaml:"request_timeout"`
	MaxRequestSize string        `yaml:"max_request_size"`
}

type RateLimitConfig

type RateLimitConfig struct {
	Enabled           bool `yaml:"enabled"`
	RequestsPerSecond int  `yaml:"requests_per_second"`
	Burst             int  `yaml:"burst"`
}

type ReplicationConfig

type ReplicationConfig struct {
	Enabled  bool     `yaml:"enabled"`
	Mode     string   `yaml:"mode"`
	Replicas []string `yaml:"replicas"`
}

type SecurityConfig

type SecurityConfig struct {
	Auth      AuthConfig      `yaml:"auth"`
	TLS       TLSConfig       `yaml:"tls"`
	RateLimit RateLimitConfig `yaml:"rate_limit"`
}

type ServerConfig

type ServerConfig struct {
	Mode      string     `yaml:"mode"`
	SwaggerUI bool       `yaml:"swaggerui,omitempty"`
	TCP       TCPConfig  `yaml:"tcp"`
	RESP      RESPConfig `yaml:"resp"`
	REST      RESTConfig `yaml:"rest"`
}

type SnapshotConfig

type SnapshotConfig struct {
	Enabled   bool          `yaml:"enabled"`
	Interval  time.Duration `yaml:"interval"`
	Directory string        `yaml:"directory"`
}

type TCPConfig

type TCPConfig struct {
	Host           string        `yaml:"host"`
	Port           int           `yaml:"port"`
	MaxConnections int           `yaml:"max_connections"`
	ReadTimeout    time.Duration `yaml:"read_timeout"`
	WriteTimeout   time.Duration `yaml:"write_timeout"`
}

type TLSConfig

type TLSConfig struct {
	Enabled  bool   `yaml:"enabled"`
	CertFile string `yaml:"cert_file"`
	KeyFile  string `yaml:"key_file"`
}

Jump to

Keyboard shortcuts

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