conf

package
v0.0.0-...-f5108b3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 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

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
}

mysql host="localhost" port=3306 database="demo" username="demo" password="demo"

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