config

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ExtensionJson = ".json"
	ExtensionYaml = ".yaml"
	ExtensionInI  = ".ini"

	NameSpace = "conf"
)
View Source
const (
	EnvTesting    = Environment("testing")
	EnvProduction = Environment("production")
)

use export ENVIRONMENT=testing set global environment

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	WebHook WebHook `mapstructure:"webhook" json:"webhook" yaml:"webhook" ini:"webhook"`
	Log     Log     `mapstructure:"log" json:"log" yaml:"log" ini:"log"`
	Email   Email   `mapstructure:"email" json:"email" yaml:"email" ini:"email"`
	System  System  `mapstructure:"system" json:"system" yaml:"system" ini:"system"`
	Mysql   Mysql   `mapstructure:"mysql" json:"mysql" yaml:"mysql" ini:"mysql"`
	Redis   Redis   `mapstructure:"redis" json:"redis" yaml:"redis" ini:"redis"`
	Etcd    Etcd    `mapstructure:"etcd" json:"etcd" yaml:"etcd" ini:"etcd"`
}

func GetConfigModels

func GetConfigModels() *Config

func LoadConfig

func LoadConfig(env, configFileName string) (*Config, error)

type Email

type Email struct {
	Port     int      `mapstructure:"port" json:"port" yaml:"port"`             // 端口
	From     string   `mapstructure:"from" json:"from" yaml:"from"`             // 收件人
	Host     string   `mapstructure:"host" json:"host" yaml:"host"`             // 服务器地址
	IsSSL    bool     `mapstructure:"is-ssl" json:"isSSL" yaml:"is-ssl"`        // 是否SSL
	Secret   string   `mapstructure:"secret" json:"secret" yaml:"secret"`       // 密钥
	Nickname string   `mapstructure:"nickname" json:"nickname" yaml:"nickname"` // 昵称
	To       []string `mapstructure:"to" json:"to" yaml:"to" ini:"to"`
}

type Environment

type Environment string

func NewGlobalEnvironment

func NewGlobalEnvironment() (Environment, error)

NewGlobalEnvironment 读取系统全局配置的环境变量

func (Environment) Invalid

func (env Environment) Invalid() bool

func (*Environment) Production

func (env *Environment) Production() Environment

func (*Environment) String

func (env *Environment) String() string

func (*Environment) Testing

func (env *Environment) Testing() Environment

type Etcd

type Etcd struct {
	Endpoints   []string `mapstructure:"endpoints" json:"endpoints" yaml:"endpoints" ini:"endpoints"`
	Username    string   `mapstructure:"username" json:"username" yaml:"username" ini:"username"`
	Password    string   `mapstructure:"password" json:"password" yaml:"password" ini:"password"`
	DialTimeout int64    `mapstructure:"dial-timeout" json:"dial-timeout" yaml:"dial-timeout" ini:"dial-timeout"`
	ReqTimeout  int64    `mapstructure:"req-timeout" json:"req-timeout" yaml:"req-timeout" ini:"req-timeout"`
}

type Log

type Log struct {
	Level         string `mapstructure:"level" json:"level" yaml:"level"`                           // 级别
	Format        string `mapstructure:"format" json:"format" yaml:"format"`                        // 输出
	Prefix        string `mapstructure:"prefix" json:"prefix" yaml:"prefix"`                        // 日志前缀
	Director      string `mapstructure:"director" json:"director"  yaml:"director"`                 // 日志文件夹
	ShowLine      bool   `mapstructure:"show-line" json:"showLine" yaml:"showLine"`                 // 显示行
	EncodeLevel   string `mapstructure:"encode-level" json:"encodeLevel" yaml:"encode-level"`       // 编码级
	StacktraceKey string `mapstructure:"stacktrace-key" json:"stacktraceKey" yaml:"stacktrace-key"` // 栈名
	LogInConsole  bool   `mapstructure:"log-in-console" json:"logInConsole" yaml:"log-in-console"`  // 输出控制台
}

type Mysql

type Mysql struct {
	Path         string `mapstructure:"path" json:"path" yaml:"path"`                             // 服务器地址
	Port         string `mapstructure:"port" json:"port" yaml:"port"`                             // 端口
	Config       string `mapstructure:"config" json:"config" yaml:"config"`                       // 高级配置
	Dbname       string `mapstructure:"db-name" json:"dbname" yaml:"db-name"`                     // 数据库名
	Username     string `mapstructure:"username" json:"username" yaml:"username"`                 // 数据库用户名
	Password     string `mapstructure:"password" json:"password" yaml:"password"`                 // 数据库密码
	MaxIdleConns int    `mapstructure:"max-idle-conns" json:"maxIdleConns" yaml:"max-idle-conns"` // 空闲中的最大连接数
	MaxOpenConns int    `mapstructure:"max-open-conns" json:"maxOpenConns" yaml:"max-open-conns"` // 打开到数据库的最大连接数
	LogMode      string `mapstructure:"log-mode" json:"logMode" yaml:"log-mode"`                  // 是否开启Gorm全局日志
	LogZap       bool   `mapstructure:"log-zap" json:"logZap" yaml:"log-zap"`                     // 是否通过zap写入日志文件
}

func (*Mysql) Dsn

func (m *Mysql) Dsn() string

func (*Mysql) EmptyDsn

func (m *Mysql) EmptyDsn() string

type Redis

type Redis struct {
	DB       int    `mapstructure:"db" json:"db" yaml:"db"`                   // redis的哪个数据库
	Addr     string `mapstructure:"addr" json:"addr" yaml:"addr"`             // 服务器地址:端口
	Password string `mapstructure:"password" json:"password" yaml:"password"` // 密码
}

type System

type System struct {
	Env     string `mapstructure:"env" json:"env" yaml:"env" ini:"env"`
	Addr    int    `mapstructure:"addr" json:"addr" yaml:"addr" ini:"addr"`
	Version string `mapstructure:"version" json:"version" yaml:"version" ini:"version"`
}

type WebHook

type WebHook struct {
	Kind string `mapstructure:"kind" json:"kind" yaml:"kind" ini:"kind"`
	Url  string `mapstructure:"url" json:"url" yaml:"url" ini:"kind"`
}

Jump to

Keyboard shortcuts

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