config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadDefault

func LoadDefault(configPath string) error

LoadDefault load configuration to the default instance

func Reset

func Reset()

Reset the default configuration instance

func SetDefault

func SetDefault(c *Config)

SetDefault the default configuration instance

Types

type Config

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

Config holds the application configuration

func Get

func Get() *Config

Get returns the default configuration instance

func Load

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

Load loads configuration from YAML file and environment variables

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.
	//  - allow use string-vars: {driver}
	Path string `yaml:"path"`
	// Use date(YYYY) as directory TODO
	DateDir bool `yaml:"date_dir"`
	// Table name for migration tracking TODO
	Table string `yaml:"table"`
}

Migrations configuration

Jump to

Keyboard shortcuts

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