Documentation
¶
Overview ¶
Package config provides database configuration types.
Index ¶
- Constants
- func Load(path string) (DBConfig, *TracingConfig, error)
- func LoadCluster(path string) (*ClusterConfig, *TracingConfig, error)
- func LoadGaussDB(path string) (*GaussDBConfig, *TracingConfig, error)
- func LoadMSSQL(path string) (*MSSQLConfig, *TracingConfig, error)
- func LoadMariaDB(path string) (*MariaDBConfig, *TracingConfig, error)
- func LoadMySQL(path string) (*MySQLConfig, *TracingConfig, error)
- func LoadOracle(path string) (*OracleConfig, *TracingConfig, error)
- func LoadPostgres(path string) (*PostgresConfig, *TracingConfig, error)
- func LoadSQLite(path string) (*SQLiteConfig, *TracingConfig, error)
- func LoadTiDB(path string) (*TiDBConfig, *TracingConfig, error)
- type BaseDBConfig
- type ClusterConfig
- type CommonNetworkConfig
- type DBConfig
- type GaussDBConfig
- type MSSQLConfig
- type MariaDBConfig
- type MySQLConfig
- type NodeConfig
- type OracleConfig
- type PoolConfig
- type PostgresConfig
- type SQLiteConfig
- type TiDBConfig
- type TracingConfig
Constants ¶
const ( LoadBalanceRoundRobin = "round_robin" LoadBalanceRandom = "random" )
const ( ExporterJaeger = "jaeger" ExporterKafka = "kafka" ExporterRedisStream = "redis_stream" )
Variables ¶
This section is empty.
Functions ¶
func Load ¶
func Load(path string) (DBConfig, *TracingConfig, error)
Load auto-detects format based on file basename and returns a DBConfig.
func LoadCluster ¶
func LoadCluster(path string) (*ClusterConfig, *TracingConfig, error)
LoadCluster loads a ClusterConfig from a file.
func LoadGaussDB ¶
func LoadGaussDB(path string) (*GaussDBConfig, *TracingConfig, error)
LoadGaussDB loads a GaussDB config from a file.
func LoadMSSQL ¶
func LoadMSSQL(path string) (*MSSQLConfig, *TracingConfig, error)
LoadMSSQL loads a MSSQL config from a file.
func LoadMariaDB ¶
func LoadMariaDB(path string) (*MariaDBConfig, *TracingConfig, error)
LoadMariaDB loads a MariaDB config from a file.
func LoadMySQL ¶
func LoadMySQL(path string) (*MySQLConfig, *TracingConfig, error)
LoadMySQL loads a MySQL config from a YAML/JSON/TOML file.
func LoadOracle ¶
func LoadOracle(path string) (*OracleConfig, *TracingConfig, error)
LoadOracle loads an Oracle config from a file.
func LoadPostgres ¶
func LoadPostgres(path string) (*PostgresConfig, *TracingConfig, error)
LoadPostgres loads a Postgres config from a file.
func LoadSQLite ¶
func LoadSQLite(path string) (*SQLiteConfig, *TracingConfig, error)
LoadSQLite loads a SQLite config from a file.
func LoadTiDB ¶
func LoadTiDB(path string) (*TiDBConfig, *TracingConfig, error)
LoadTiDB loads a TiDB config from a file.
Types ¶
type BaseDBConfig ¶
type BaseDBConfig struct {
CommonNetworkConfig `yaml:",inline" json:",inline" toml:",inline"`
Pool *PoolConfig `yaml:"pool,omitempty" json:"pool,omitempty" toml:"pool,omitempty"`
Tracing *TracingConfig `yaml:"tracing,omitempty" json:"tracing,omitempty" toml:"tracing,omitempty"`
}
BaseDBConfig embeds CommonNetworkConfig, PoolConfig, and TracingConfig.
func (*BaseDBConfig) DSN ¶
func (b *BaseDBConfig) DSN() string
DSN builds a default MySQL-style DSN from CommonNetworkConfig.
func (*BaseDBConfig) GetPool ¶
func (b *BaseDBConfig) GetPool() *PoolConfig
func (*BaseDBConfig) GetTracing ¶
func (b *BaseDBConfig) GetTracing() *TracingConfig
type ClusterConfig ¶
type ClusterConfig struct {
Driver string `yaml:"driver" json:"driver" toml:"driver"`
Sources []NodeConfig `yaml:"sources" json:"sources" toml:"sources"`
Replicas []NodeConfig `yaml:"replicas,omitempty" json:"replicas,omitempty" toml:"replicas,omitempty"`
LoadBalance string `yaml:"load_balance" json:"load_balance" toml:"load_balance"`
Pool *PoolConfig `yaml:"pool,omitempty" json:"pool,omitempty" toml:"pool,omitempty"`
Tracing *TracingConfig `yaml:"tracing,omitempty" json:"tracing,omitempty" toml:"tracing,omitempty"`
}
ClusterConfig holds configuration for cluster (read/write splitting) access.
func (*ClusterConfig) Validate ¶
func (cc *ClusterConfig) Validate() error
Validate validates ClusterConfig, setting defaults.
type CommonNetworkConfig ¶
type CommonNetworkConfig struct {
Host string `yaml:"host" json:"host" toml:"host"`
Port int `yaml:"port" json:"port" toml:"port"`
Username string `yaml:"username" json:"username" toml:"username"`
Password string `yaml:"password" json:"-" toml:"password"`
Database string `yaml:"database" json:"database" toml:"database"`
}
CommonNetworkConfig holds network connection fields shared by 7/8 databases.
func (*CommonNetworkConfig) DSN ¶
func (c *CommonNetworkConfig) DSN() string
DSN builds a default MySQL-style DSN.
type DBConfig ¶
type DBConfig interface {
DriverName() string
DSN() string
Validate() error
GetPool() *PoolConfig
GetTracing() *TracingConfig
}
DBConfig is the unified interface for all 8 database config types.
type GaussDBConfig ¶
type GaussDBConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
SSLMode string `yaml:"ssl_mode" json:"ssl_mode" toml:"ssl_mode"`
Schema string `yaml:"schema" json:"schema" toml:"schema"`
}
GaussDBConfig implements DBConfig for Huawei GaussDB (wire-compatible with PostgreSQL).
func (*GaussDBConfig) DSN ¶
func (c *GaussDBConfig) DSN() string
DSN builds a GaussDB DSN string (PostgreSQL wire-compatible, no TimeZone).
func (*GaussDBConfig) DriverName ¶
func (c *GaussDBConfig) DriverName() string
DriverName returns the driver name.
func (*GaussDBConfig) Validate ¶
func (c *GaussDBConfig) Validate() error
Validate validates the config and sets defaults.
type MSSQLConfig ¶
type MSSQLConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
Instance string `yaml:"instance" json:"instance" toml:"instance"`
}
MSSQLConfig implements DBConfig for Microsoft SQL Server.
func (*MSSQLConfig) DSN ¶
func (c *MSSQLConfig) DSN() string
DSN builds a SQL Server connection string.
func (*MSSQLConfig) DriverName ¶
func (c *MSSQLConfig) DriverName() string
DriverName returns the driver name.
func (*MSSQLConfig) Validate ¶
func (c *MSSQLConfig) Validate() error
Validate validates the config and sets defaults.
type MariaDBConfig ¶
type MariaDBConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
Charset string `yaml:"charset" json:"charset" toml:"charset"`
}
MariaDBConfig implements DBConfig for MariaDB (wire-compatible with MySQL).
func (*MariaDBConfig) DriverName ¶
func (c *MariaDBConfig) DriverName() string
DriverName returns the driver name.
func (*MariaDBConfig) Validate ¶
func (c *MariaDBConfig) Validate() error
Validate validates the config, setting defaults.
type MySQLConfig ¶
type MySQLConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
Charset string `yaml:"charset" json:"charset" toml:"charset"`
}
MySQLConfig implements DBConfig for MySQL.
func (*MySQLConfig) DriverName ¶
func (c *MySQLConfig) DriverName() string
DriverName returns the driver name.
func (*MySQLConfig) Validate ¶
func (c *MySQLConfig) Validate() error
Validate validates the config, setting defaults.
type NodeConfig ¶
type NodeConfig struct {
Host string `yaml:"host" json:"host" toml:"host"`
Port int `yaml:"port" json:"port" toml:"port"`
Username string `yaml:"username" json:"username" toml:"username"`
Password string `yaml:"password" json:"-" toml:"password"`
Database string `yaml:"database" json:"database" toml:"database"`
// Expanded fields per driver
Instance string `yaml:"instance,omitempty" json:"instance,omitempty" toml:"instance,omitempty"`
ServiceName string `yaml:"service_name,omitempty" json:"service_name,omitempty" toml:"service_name,omitempty"`
SID string `yaml:"sid,omitempty" json:"sid,omitempty" toml:"sid,omitempty"`
SSLMode string `yaml:"ssl_mode,omitempty" json:"ssl_mode,omitempty" toml:"ssl_mode,omitempty"`
Schema string `yaml:"schema,omitempty" json:"schema,omitempty" toml:"schema,omitempty"`
}
NodeConfig holds a single database node connection info for cluster use.
func (*NodeConfig) DSN ¶
func (n *NodeConfig) DSN() string
DSN builds a DSN from NodeConfig using MySQL-style format (overridden per driver if needed).
type OracleConfig ¶
type OracleConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
ServiceName string `yaml:"service_name" json:"service_name" toml:"service_name"`
SID string `yaml:"sid" json:"sid" toml:"sid"`
}
OracleConfig implements DBConfig for Oracle Database.
func (*OracleConfig) DSN ¶
func (c *OracleConfig) DSN() string
DSN builds an Oracle connection string.
func (*OracleConfig) DriverName ¶
func (c *OracleConfig) DriverName() string
DriverName returns the driver name.
func (*OracleConfig) Validate ¶
func (c *OracleConfig) Validate() error
Validate validates the config and sets defaults.
type PoolConfig ¶
type PoolConfig struct {
MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns" toml:"max_open_conns"`
MaxIdleConns int `yaml:"max_idle_conns" json:"max_idle_conns" toml:"max_idle_conns"`
ConnMaxLifetime int `yaml:"conn_max_lifetime" json:"conn_max_lifetime" toml:"conn_max_lifetime"`
ConnMaxIdleTime int `yaml:"conn_max_idle_time" json:"conn_max_idle_time" toml:"conn_max_idle_time"`
}
PoolConfig holds database connection pool settings.
func (*PoolConfig) ConnMaxIdleTimeDuration ¶
func (p *PoolConfig) ConnMaxIdleTimeDuration() time.Duration
ConnMaxIdleTimeDuration returns ConnMaxIdleTime as time.Duration.
func (*PoolConfig) ConnMaxLifetimeDuration ¶
func (p *PoolConfig) ConnMaxLifetimeDuration() time.Duration
ConnMaxLifetimeDuration returns ConnMaxLifetime as time.Duration.
func (*PoolConfig) Validate ¶
func (p *PoolConfig) Validate() error
Validate sets defaults and validates PoolConfig.
type PostgresConfig ¶
type PostgresConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
SSLMode string `yaml:"ssl_mode" json:"ssl_mode" toml:"ssl_mode"`
TimeZone string `yaml:"timezone" json:"timezone" toml:"timezone"`
Schema string `yaml:"schema" json:"schema" toml:"schema"`
}
PostgresConfig implements DBConfig for PostgreSQL.
func (*PostgresConfig) DSN ¶
func (c *PostgresConfig) DSN() string
DSN builds a PostgreSQL connection string.
func (*PostgresConfig) DriverName ¶
func (c *PostgresConfig) DriverName() string
DriverName returns the driver name.
func (*PostgresConfig) Validate ¶
func (c *PostgresConfig) Validate() error
Validate validates the config and sets defaults.
type SQLiteConfig ¶
type SQLiteConfig struct {
Path string `yaml:"path" json:"path" toml:"path"`
Pool *PoolConfig `yaml:"pool,omitempty" json:"pool,omitempty" toml:"pool,omitempty"`
Tracing *TracingConfig `yaml:"tracing,omitempty" json:"tracing,omitempty" toml:"tracing,omitempty"`
}
SQLiteConfig implements DBConfig for SQLite (file-based, no network fields).
func (*SQLiteConfig) DriverName ¶
func (c *SQLiteConfig) DriverName() string
DriverName returns the driver name.
func (*SQLiteConfig) GetPool ¶
func (c *SQLiteConfig) GetPool() *PoolConfig
GetPool returns the pool config.
func (*SQLiteConfig) GetTracing ¶
func (c *SQLiteConfig) GetTracing() *TracingConfig
GetTracing returns the tracing config.
func (*SQLiteConfig) Validate ¶
func (c *SQLiteConfig) Validate() error
Validate validates the config.
type TiDBConfig ¶
type TiDBConfig struct {
BaseDBConfig `yaml:",inline" json:",inline" toml:",inline"`
Charset string `yaml:"charset" json:"charset" toml:"charset"`
}
TiDBConfig implements DBConfig for TiDB (wire-compatible with MySQL).
func (*TiDBConfig) DriverName ¶
func (c *TiDBConfig) DriverName() string
DriverName returns the driver name.
func (*TiDBConfig) Validate ¶
func (c *TiDBConfig) Validate() error
Validate validates the config, setting defaults.
type TracingConfig ¶
type TracingConfig struct {
Enabled bool `yaml:"enabled" json:"enabled" toml:"enabled"`
Service string `yaml:"service" json:"service" toml:"service"`
Exporter string `yaml:"exporter" json:"exporter" toml:"exporter"`
Endpoint string `yaml:"endpoint" json:"endpoint" toml:"endpoint"`
Protocol string `yaml:"protocol" json:"protocol" toml:"protocol"`
SamplerType string `yaml:"sampler_type" json:"sampler_type" toml:"sampler_type"`
SamplerRatio float64 `yaml:"sampler_ratio" json:"sampler_ratio" toml:"sampler_ratio"`
// Kafka-specific
Topic string `yaml:"topic" json:"topic" toml:"topic"`
// Redis-specific
Stream string `yaml:"stream" json:"stream" toml:"stream"`
RedisPassword string `yaml:"redis_password" json:"-" toml:"redis_password"`
}
TracingConfig holds OpenTelemetry tracing export configuration.
func (*TracingConfig) Validate ¶
func (tc *TracingConfig) Validate() error
Validate sets defaults and validates TracingConfig.