Documentation
¶
Overview ¶
Package config provides shared SQL (github.com/alexfalkowski/go-service/v2/database/sql) configuration types for go-service.
This package defines configuration structs that are typically embedded into a larger service configuration and then consumed by driver-specific wiring (for example github.com/alexfalkowski/go-service/v2/database/sql/pg).
Pool configuration ¶
The top-level Config models common connection pool settings such as:
- maximum connection lifetime,
- max open connections, and
- max idle connections.
DSNs and source strings ¶
Writer and replica (reader) DSNs are configured via DSN entries. Each DSN URL is expressed as a go-service "source string" (resolved via github.com/alexfalkowski/go-service/v2/os.FS.ReadSource), so it can be:
- "env:NAME" to read from an environment variable,
- "file:/path/to/dsn" to read from a file, or
- any other value treated as a literal DSN.
Enabled SQL configurations must provide at least one writer or reader DSN, and each resolved DSN must be non-empty.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Writers is the set of primary (read-write) datasource DSNs.
//
// Each DSN URL is a "source string" resolved via [os.FS.ReadSource], so it can be:
// - "env:NAME" to read the DSN from an environment variable,
// - "file:/path/to/dsn" to read the DSN from a file, or
// - any other value treated as a literal DSN string.
Writers []DSN `yaml:"writers,omitempty" json:"writers,omitempty" toml:"writers,omitempty"`
// Readers is the set of replica (read-only) datasource DSNs.
//
// Each DSN URL is a "source string" resolved via [os.FS.ReadSource] (see [Config.Writers] for the supported formats).
Readers []DSN `yaml:"readers,omitempty" json:"readers,omitempty" toml:"readers,omitempty"`
// ConnMaxLifetime is the maximum amount of time a connection may be reused.
//
// In config files it is encoded as a Go duration string (for example "30s", "5m", "1h").
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime,omitempty" json:"conn_max_lifetime,omitempty" toml:"conn_max_lifetime,omitempty" validate:"gte=0"`
// MaxOpenConns is the maximum number of open connections to the database.
MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns" toml:"max_open_conns" validate:"gt=0"`
// MaxIdleConns is the maximum number of connections in the idle connection pool.
MaxIdleConns int `yaml:"max_idle_conns" json:"max_idle_conns" toml:"max_idle_conns" validate:"gt=0,ltefield=MaxOpenConns"`
}
Config contains shared github.com/alexfalkowski/go-service/v2/database/sql connection pool configuration.
It is intended to be embedded by driver-specific configuration types (for example PostgreSQL) and consumed by the SQL wiring in this repository.
Config.Writers and Config.Readers contain DSNs (connection strings) expressed as go-service "source strings" (literal values, `file:` paths, or `env:` references) that are resolved by os.FS.ReadSource. Enabled SQL configurations must provide at least one writer or reader DSN, and each resolved DSN must be non-empty.
type DSN ¶
type DSN struct {
// URL is a go-service "source string" for the datasource name/connection string.
//
// It is resolved via [os.FS.ReadSource], so it can be:
// - "env:NAME" to read from an environment variable,
// - "file:/path/to/dsn" to read from a file, or
// - any other value treated as a literal connection string.
URL string `yaml:"url,omitempty" json:"url,omitempty" toml:"url,omitempty"`
}
DSN is a SQL datasource name (connection string) configuration.