Documentation
¶
Overview ¶
Package config provides configuration loading and validation for go-migration. It supports YAML files, JSON files, and environment variables.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConfigValidation = errors.New("configuration validation failed")
ErrConfigValidation is returned when configuration validation fails.
Functions ¶
func InterpolateEnv ¶
InterpolateEnv replaces ${VAR_NAME} placeholders in data with the corresponding environment variable values. Escaped sequences ($${VAR_NAME}) are replaced with the literal text ${VAR_NAME}. Returns an error listing all unresolved variables.
When a quoted JSON string consists entirely of a single placeholder (e.g. "${DB_PORT}") and the resolved value is a number, boolean, or null, the surrounding quotes are removed so that the JSON remains valid. For example, "port": "${DB_PORT}" with DB_PORT=5433 becomes "port": 5433.
Types ¶
type Config ¶
type Config struct {
Connections map[string]ConnectionConfig `yaml:"connections" json:"connections"`
DefaultConn string `yaml:"default" json:"default"`
MigrationTable string `yaml:"migration_table" json:"migration_table"`
MigrationDir string `yaml:"migration_dir" json:"migration_dir"`
SeederDir string `yaml:"seeder_dir" json:"seeder_dir"`
FactoryDir string `yaml:"factory_dir" json:"factory_dir"`
LogLevel string `yaml:"log_level" json:"log_level"`
LogOutput string `yaml:"log_output" json:"log_output"`
}
Config holds the top-level configuration for go-migration.
func Load ¶
Load reads configuration from a file at the given path. It detects the format by file extension (.yaml/.yml for YAML, .json for JSON). After loading, it applies defaults.
func LoadFromEnv ¶
LoadFromEnv builds a Config from environment variables with the GOMIGRATE_ prefix. It creates a single "default" connection from the DB-related env vars. After loading, it applies defaults.
func (*Config) ApplyDefaults ¶
func (c *Config) ApplyDefaults()
ApplyDefaults sets sensible default values for optional settings.
type ConnectionConfig ¶
type ConnectionConfig struct {
Driver string `yaml:"driver" json:"driver"`
Host string `yaml:"host" json:"host"`
Port int `yaml:"port" json:"port"`
Database string `yaml:"database" json:"database"`
Username string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
MaxOpenConns int `yaml:"max_open_conns" json:"max_open_conns"`
MaxIdleConns int `yaml:"max_idle_conns" json:"max_idle_conns"`
ConnMaxLifetime time.Duration `yaml:"conn_max_lifetime" json:"conn_max_lifetime"`
Options map[string]string `yaml:"options" json:"options"`
}
ConnectionConfig holds the configuration for a single database connection.