conf

package
v0.0.0-...-852afa5 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TextFormat 文本格式
	TextFormat = LogFormat("text")
	// JSONFormat json格式
	JSONFormat = LogFormat("json")
)
View Source
const (
	// ToFile 保存到文件
	ToFile = LogTo("file")
	// ToStdout 打印到标准输出
	ToStdout = LogTo("stdout")
)

Variables

This section is empty.

Functions

func LoadConfigFromEnv

func LoadConfigFromEnv() error

完成环境变量到 Config 对象的映射

func LoadConfigFromToml

func LoadConfigFromToml(filePath string) error

完成 toml 配置文件到 Config 对象的映射

Types

type App

type App struct {
	Name      string `toml:"name" env:"APP_NAME"`
	Host      string `toml:"host" env:"APP_HOST"`
	Port      string `toml:"port" env:"APP_PORT"`
	Key       string `toml:"key" env:"APP_KEY"`
	EnableSSL bool   `toml:"enable_ssl" env:"APP_ENABLE_SSL"`
	CertFile  string `toml:"cert_file" env:"APP_CERT_FILE"`
	KeyFile   string `toml:"key_file" env:"APP_KEY_FILE"`
}

func NewDefaultApp

func NewDefaultApp() *App

默认的 App 配置

type Config

type Config struct {
	App   *App   `toml:"app"`
	Log   *Log   `toml:"log"`
	MySQL *MySQL `toml:"mysql"`
}

Config 应用配置

func C

func C() *Config

func NewDefaultConfig

func NewDefaultConfig() *Config

默认的 Config 配置

type Log

type Log struct {
	Level   string    `toml:"level" env:"LOG_LEVEL"`
	PathDir string    `toml:"path_dir" env:"LOG_PATH_DIR"`
	Format  LogFormat `toml:"format" env:"LOG_FORMAT"`
	To      LogTo     `toml:"to" env:"LOG_TO"`
}

func NewDefaultLog

func NewDefaultLog() *Log

默认的 Log 配置

type LogFormat

type LogFormat string

LogFormat 日志格式

type LogTo

type LogTo string

LogTo 日志记录到哪儿

type MySQL

type MySQL struct {
	Host     string `toml:"host" env:"MYSQL_HOST"`
	Port     string `toml:"port" env:"MYSQL_PORT"`
	UserName string `toml:"username" env:"MYSQL_USERNAME"`
	Password string `toml:"password" env:"MYSQL_PASSWORD"`
	Database string `toml:"database" env:"MYSQL_DATABASE"`
	// 使用 MySQL 连接池, 需要做一些规划配置
	// 控制当前程序 MySQL 打开的连接数
	MaxOpenConn int `toml:"max_open_conn" env:"MYSQL_MAX_OPEN_CONN"`
	// 控制 MySQL 打开的连接数
	MaxIdleConn int `toml:"max_idle_conn" env:"MYSQL_MAX_IDLE_CONN"`
	// 一个连接的生命周期, 这个和 MySQL Server 的配置有关, 必须小于 Server 的配置
	MaxLifeTime int `toml:"max_life_time" env:"MYSQL_MAX_LIFE_TIME"`
	// Idle 连接最多允许存活多久
	MaxIdleTime int `toml:"max_idle_time" env:"MYSQL_MAX_IDLE_TIME"`
	// contains filtered or unexported fields
}

func NewDefaultMySQL

func NewDefaultMySQL() *MySQL

默认的 MySQL 配置

func (*MySQL) GetDB

func (m *MySQL) GetDB() (*sql.DB, error)

GetDB todo

Jump to

Keyboard shortcuts

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