Documentation
¶
Index ¶
Constants ¶
View Source
const (
// 模块名称
AppName = "conf"
)
Variables ¶
This section is empty.
Functions ¶
func LoadFromFile ¶
该文件定义 配置对象的加载方法 github.com/BurntSushi/toml go里使用比较广泛的toml格式解析库 https://github.com/BurntSushi/toml 查看该库的基本用法 object <---> toml 配置文件
Types ¶
type Application ¶
type Application struct {
Domain string `json:"domain" yaml:"domain" toml:"domain" env:"APP_DOMAIN"`
}
type Config ¶
type Config struct { Application *Application `json:"app" yaml:"app" toml:"app"` MySQL *MySQL `json:"mysql" yaml:"mysql" toml:"mysql"` GrpcServer *GrpcServer `json:"grpc" yaml:"grpc" toml:"grpc"` }
程序配置对象, 启动时 会读取配置, 并且为程序提供需要全局变量 把配置对象做出全局变量(单列模式)
toml
mysql host="127.0.0.1" port=3306 ...
func DefaultConfig ¶
func DefaultConfig() *Config
type GrpcServer ¶
type GrpcServer struct { Host string `json:"host" yaml:"host" toml:"host"` Port int `json:"port" yaml:"port" toml:"port"` // contains filtered or unexported fields }
func (*GrpcServer) Address ¶
func (s *GrpcServer) Address() string
func (*GrpcServer) GetServer ¶
func (s *GrpcServer) GetServer() *grpc.Server
func (*GrpcServer) Start ¶
func (s *GrpcServer) Start()
type MySQL ¶
type MySQL struct { Host string `json:"host" yaml:"host" toml:"host" env:"DATASOURCE_HOST"` Port int `json:"port" yaml:"port" toml:"port" env:"DATASOURCE_PORT"` DB string `json:"database" yaml:"database" toml:"database" env:"DATASOURCE_DB"` Username string `json:"username" yaml:"username" toml:"username" env:"DATASOURCE_USERNAME"` Password string `json:"password" yaml:"password" toml:"password" env:"DATASOURCE_PASSWORD"` Debug bool `json:"debug" yaml:"debug" toml:"debug" env:"DATASOURCE_DEBUG"` // contains filtered or unexported fields }
db对象也是一个单列模式
Click to show internal directories.
Click to hide internal directories.