config

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	ConfigFile string     `yaml:"-"` // internal use
	Verbose    bool       `yaml:"verbose"`
	Database   Database   `yaml:"database"`
	Migrations Migrations `yaml:"migrations"`
}

Config holds the application configuration

func Load

func Load(configFile string) (*Config, error)

Load loads configuration from YAML file and environment variables

  • configFile: if not exist, will skip load it.

NOTE: will auto load .env file on working directory.

type Database

type Database struct {
	// Driver name for database. 标准数据库类型名称。
	//
	// eg: mysql, postgres, sqlite, mssql, ...
	//
	// NOTE: 当使用的驱动库注册名称不一致时,需要配置 SqlDriver 用于 sql.Open()
	Driver string `yaml:"driver"`
	// SqlDriver sql driver name. 数据库驱动库注册到 database/sql 的名称
	//
	// NOTE: 跟使用的数据库驱动库有关
	SqlDriver string `yaml:"sql_driver" json:"sql_driver"`
	// DSN 连接配置
	DSN string `yaml:"dsn"`

	// 可以使用拆分配置项 - DSN 为空时,会跟据下面的信息构建DSN
	Host     string `yaml:"host" json:"host"`
	Port     int    `yaml:"port" json:"port"`
	User     string `yaml:"user" json:"user"`
	Password string `yaml:"password" json:"password"`
	DBName   string `yaml:"dbname" json:"dbname"`
	SSLMode  string `yaml:"ssl_mode" json:"ssl_mode"`

	// Connection pool settings
	MaxIdleConns    int `yaml:"max_idle_conns" json:"max_idle_conns"`
	MaxOpenConns    int `yaml:"max_open_conns" json:"max_open_conns"`
	ConnMaxIdleTime int `yaml:"conn_max_idle_time" json:"conn_max_idle_time"`
	ConnMaxLifetime int `yaml:"conn_max_lifetime" json:"conn_max_lifetime"`
}

Database configuration

type Migrations

type Migrations struct {
	// Path to the migrations file directory. default: ./migrations
	//  - allow multiple paths separated by comma.
	//  - allow use string-vars: {driver}
	//  - allow use ENV-vars: ${APP_MODULE}
	Path string `yaml:"path"`
	// Table name for migration record table TODO
	Table string `yaml:"table"`
	// Recursive search for migration SQL files. default: true
	Recursive bool `yaml:"recursive"`
}

Migrations configuration

func (*Migrations) GetPaths added in v0.2.1

func (m *Migrations) GetPaths() []string

GetPaths get migration paths

Jump to

Keyboard shortcuts

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