conf

package
v0.0.0-...-19fd678 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TextFormat = LogFormat("text")
	JSONFormat = LogFormat("json")
)
View Source
const (
	ToFile   = LogTo("file")
	ToStdout = LogTo("stdout")
)
View Source
const AppservicesPath = "/Users/chartte/go/src/mage/restful-api-demo/etc/appservice.json"
View Source
const GlobalConfig = "/Users/chartte/go/src/mage/restful-api-demo/etc/demo.toml"

Variables

This section is empty.

Functions

func LoadConfigFromEnv

func LoadConfigFromEnv() error

从环境变量中读取

func LoadConfigFromToml

func LoadConfigFromToml(filePath string) error

从文件中读取

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"`
}

func NewDefaultApp

func NewDefaultApp() *App

func (*App) HttpAddr

func (a *App) HttpAddr() string

type Config

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

将所有应用配置封装成一个对象,来与外部配置

func C

func C() *Config

获取配置

func NewDefaultConfig

func NewDefaultConfig() *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

type LogFormat

type LogFormat string

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"`
	MaxOpenConn int    `toml:"max_open_conn" env:"MYSQL_MAX_OPEN_CONN"`
	MaxIdleConn int    `toml:"max_idle_conn" env:"MYSQL_MAX_IDLE_CONN"`
	MaxLifeTime int    `toml:"max_life_time" env:"MYSQL_MAX_LIFE_TIME"`
	MaxIdleTime int    `toml:"max_idle_time" env:"MYSQL_MAX_idle_TIME"`
}

func NewDefaultMySQL

func NewDefaultMySQL() *MySQL

func (*MySQL) GetDB

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

主要用于获取数据库连接,并维护一个全局的数据库连接,确保多次调用返回的是同一个连接。

type ServiceConfig

type ServiceConfig struct {
	Services []ServiceInfo
}

type ServiceInfo

type ServiceInfo struct {
	Name      string `json:"name"`
	Interface string `json:"interface"`
	Enabled   bool   `json:"enabled"`
}

Jump to

Keyboard shortcuts

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