conf

package
v0.0.0-...-28af436 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfigFromEnv

func LoadConfigFromEnv() error

负责加载配置

func LoadConfigFromToml

func LoadConfigFromToml(filepath string) error

负责加载配置 直接定义函数,从文件里面加载

Types

type App

type App struct {
	HttpHost string `json:"http_host" env:"HTTP_HOST"`
	HttpPort int64  `json:"http_port" env:"HTTP_PORT"`
}

func (*App) HttpAddr

func (a *App) HttpAddr() string

type Config

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

这个对象维护整个程序配置

func C

func C() *Config

func DefaultConfig

func DefaultConfig() *Config

程序默认配置

func (*Config) String

func (c *Config) String() string

为Config对象加一个方法,如果说这个对象默认打印的是一个指针,而你又想打印字符串的时候可以实现一个String方法

type MySQL

type MySQL struct {
	Host     string `json:"host" toml:"host" env:"MYSQL_HOST"`
	Port     int    `json:"port" toml:"port" env:"MYSQL_PORT"`
	DB       string `json:"database" toml:"database" env:"MYSQL_DB"`
	Username string `json:"username" toml:"username" env:"MYSQL_USERNAME"`
	Password string `json:"password" toml:"password" env:"MYSQL_PASSWORD"`
	// contains filtered or unexported fields
}

func (*MySQL) DSN

func (m *MySQL) DSN() string

参考 https://github.com/go-sql-driver/mysql#dsn-data-source-name 获取详情 dsn := "user:pass@tcp(127.0.0.1:3306)/dbname?charset=utf8mb4&parseTime=True&loc=Local"

func (*MySQL) GetConn

func (m *MySQL) GetConn() *gorm.DB

返回一个数据库链接, 返回一个全局单列

Jump to

Keyboard shortcuts

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