settings

package
v0.0.0-...-357760b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultConfEnvPath = "./configs/dev/"
)

默认读取配置文件路径

Variables

View Source
var (
	ConfBase = new(BaseConfig)
	//ConfMySQL    = new(MySQLConfig)
	ConfMySQLMap = new(MySQLMapConfig)
	//ConfRedis    = new(RedisConfig)
	ConfRedisMap = new(RedisMapConfig)
	ViperConfMap map[string]*viper.Viper
)

配置信息全局变量

View Source
var (
	ConfEnvPath string // 配置文件路径
	ConfEnv     string // 模式
)

配置文件全局变量

View Source
var (
	TimeLocation *time.Location
	TimeFormat   = "2006-01-02 15:04:05"
	DateFormat   = "2006-01-02"
	LocalIP      = net.ParseIP("127.0.0.1")
)

全局变量

Functions

func Encode

func Encode(data string) (string, error)

Encode description

func GetBoolConf

func GetBoolConf(key string) bool

GetBoolConf 获取 bool 类型配置信息

func GetConfEnv

func GetConfEnv() string

GetConfEnv 获取配置环境名

func GetConfFile

func GetConfFile(fileName string) string

GetConfFile 获取带后缀名的路径

func GetConfFilePath

func GetConfFilePath(fileName string) string

GetConfFilePath 获取文件路径

func GetConfPath

func GetConfPath() string

GetConfPath 获取配置目录路径

func GetDurationConf

func GetDurationConf(key string) time.Duration

GetDurationConf 获取时间阶段长度

func GetFloat64Conf

func GetFloat64Conf(key string) float64

GetFloat64Conf 获取 float64 类型配置信息

func GetIntConf

func GetIntConf(key string) int

GetIntConf 获取 int 类型配置信息

func GetLocalIPs

func GetLocalIPs() (ips []net.IP)

GetLocalIPs 获取 IP 列表

func GetMd5Hash

func GetMd5Hash(text string) string

GetMd5Hash description

func GetStringConf

func GetStringConf(key string) string

GetStringConf 获取 string 类型配置信息

func GetStringMapConf

func GetStringMapConf(key string) map[string]interface{}

GetStringMapConf 获取 string 为 key 的 map 类型信息

func GetStringMapStringConf

func GetStringMapStringConf(key string) map[string]string

GetStringMapStringConf 获取 map[string]string 类型配置信息

func GetStringSliceConf

func GetStringSliceConf(key string) []string

GetStringSliceConf 获取 []string 类型配置信息

func GetTimeConf

func GetTimeConf(key string) time.Time

GetTimeConf 获取 time.Time 类型配置信息

func InArrayString

func InArrayString(s string, arr []string) bool

InArrayString descryption

func Init

func Init(configPath string) error

Init 公共初始化函数,支持两种方法设置配置文件

函数传入配置文件 Init("./configs/dev/") 如果配置文件为空,会重命令行读取 -config conf/dev/ 1. 加载配置(base、mysql、redis etc...) 2. 初始化日志

func InitModule

func InitModule(configPath string, modules []string) error

InitModule 模块初始化 1. 加载 base 配置 2. 加载 mysql 配置 3. 加载 redis 配置 4. 初始化日志

func IsSetConf

func IsSetConf(key string) bool

IsSetConf 是否设置了key

func ParseConfPath

func ParseConfPath(config string) error

ParseConfPath 解析配置文件目录

配置文件必须放到一个文件夹中 如:config=conf/dev/base.json ConfEnvPath=conf/dev ConfEnv=dev 如:config=conf/base.json ConfEnvPath=conf ConfEnv=conf

func ParseConfig

func ParseConfig(path string, fileName string, conf interface{}) (err error)

ParseConfig 解析本地配置文件

func ParseLocalConfig

func ParseLocalConfig(fileName string, st interface{}) error

ParseLocalConfig 解析本地文件

Types

type BaseConfig

type BaseConfig struct {
	Name         string `mapstructure:"name"`
	Mode         string `mapstructure:"mode"`
	Version      string `mapstructure:"version"`
	StartTime    string `mapstructure:"start_time"`
	TimeLocation string `mapstructure:"time_location"`
	MachineID    int64  `mapstructure:"machine_id"`
	Port         int    `mapstructure:"port"`

	*LogConfig `mapstructure:"log"`
}

BaseConfig 应用程序配置信息

func GetBaseConf

func GetBaseConf() *BaseConfig

GetBaseConf 获取基本配置信息

type LogConfig

type LogConfig struct {
	Level      string `mapstructure:"level"`
	Filename   string `mapstructure:"filename"`
	MaxSize    int    `mapstructure:"max_size"`
	MaxAge     int    `mapstructure:"max_age"`
	MaxBackups int    `mapstructure:"max_backup"`
}

LogConfig Zap 配置信息

type MySQLConfig

type MySQLConfig struct {
	Host         string `mapstructure:"host"`
	User         string `mapstructure:"user"`
	Password     string `mapstructure:"password"`
	DbName       string `mapstructure:"dbname"`
	Port         int    `mapstructure:"port"`
	MaxOpenConns int    `mapstructure:"max_open_conns"`
	MaxIdleConns int    `mapstructure:"max_idel_conns"`
}

MySQLConfig MySQL 配置信息

type MySQLMapConfig

type MySQLMapConfig struct {
	List map[string]*MySQLConfig `mapstructure:"list"`
}

MySQLMapConfig 数据库列表

type RedisConfig

type RedisConfig struct {
	Host     string `mapstructure:"host"`
	Password string `mapstructure:"password"`
	Port     int    `mapstructure:"port"`
	DB       int    `mapstructure:"db"`
	PoolSize int    `mapstructure:"pool_size"`
}

RedisConfig Redis 配置信息

type RedisMapConfig

type RedisMapConfig struct {
	List map[string]*RedisConfig `mapstructure:"list"`
}

RedisMapConfig Redis 列表

Jump to

Keyboard shortcuts

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