settings

package
v0.0.0-...-2828958 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 28 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 (
	DBMapPool       map[string]*sqlx.DB
	GORMMapPool     map[string]*gorm.DB
	DBDefaultPool   *sqlx.DB
	GORMDefaultPool *gorm.DB
)

全局变量

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 Close

func Close() error

Close 关闭 DB 连接

func ConfDo

func ConfDo(trace *mylog.TraceContext, name string, commandName string, args ...interface{}) (interface{}, error)

ConfDo 通过配置 执行redis

func ConnFactory

func ConnFactory(name string) (redis.Conn, error)

ConnFactory 获取连接

func Destroy

func Destroy()

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 GetDBPool

func GetDBPool(name string) (*sqlx.DB, error)

GetDBPool 获取一个默认连接

func GetDurationConf

func GetDurationConf(key string) time.Duration

GetDurationConf 获取时间阶段长度

func GetFloat64Conf

func GetFloat64Conf(key string) float64

GetFloat64Conf 获取 float64 类型配置信息

func GetGormPool

func GetGormPool(name string) (*gorm.DB, error)

GetGormPool 从连接中获取一个默认连接

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 InitDBPool

func InitDBPool() error

InitDBPool 初始化数据库连接池

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 LogDo

func LogDo(trace *mylog.TraceContext, c redis.Conn, commandName string, args ...interface{}) (interface{}, error)

LogDo 带有日志的 Do 方法

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 解析本地文件

func SqlxLogExec

func SqlxLogExec(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string,
	args ...interface{}) (sql.Result, error)

SqlxLogExec 执行 sql 并记录日志

func SqlxLogGet

func SqlxLogGet(trace *mylog.TraceContext, sqlDB *sqlx.DB, dest interface{}, query string,
	args ...interface{}) error

SqlxLogGet 单行查询并记录日志

func SqlxLogNamedExec

func SqlxLogNamedExec(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string,
	arg interface{}) (sql.Result, error)

SqlxLogNamedExec 执行 sql 并记录日志

func SqlxLogNamedQuery

func SqlxLogNamedQuery(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string,
	arg interface{}) (*sqlx.Rows, error)

SqlxLogNamedQuery 查询并记录日志

func SqlxLogQuery

func SqlxLogQuery(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string,
	args ...interface{}) (*sql.Rows, error)

SqlxLogQuery 查询并记录日志

func SqlxLogSelect

func SqlxLogSelect(trace *mylog.TraceContext, sqlDB *sqlx.DB, dest interface{}, query string,
	args ...interface{}) error

SqlxLogSelect 多行查询并记录日志

func SqlxLogTxExec

func SqlxLogTxExec(trace *mylog.TraceContext, tx *sqlx.Tx, query string,
	args ...interface{}) (sql.Result, error)

SqlxLogTxExec 执行事务 sql 并记录日志

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"`
	*HttpConfig    `mapstructure:"http"`
	*SessionConfig `mapstructure:"session"`
	*SwagConfig    `mapstructure:"swagger"`
	*ClusterConfig `mapstructure:"cluster"`
}

BaseConfig 应用程序配置信息

func GetBaseConf

func GetBaseConf() *BaseConfig

GetBaseConf 获取基本配置信息

type ClusterConfig

type ClusterConfig struct {
	ClusterIP      string `mapstructure:"cluster_ip"`
	ClusterPost    string `mapstructure:"cluster_port"`
	ClusterSslPort string `mapstructure:"cluster_ssl_port"`
}

type GormLogger

type GormLogger struct {
	gorm.Logger
	Trace *mylog.TraceContext
}

GormLogger MySQL 日志打印类 Logger default logger

func (*GormLogger) LogFormatter

func (logger *GormLogger) LogFormatter(values ...interface{}) (messages map[string]interface{})

LogFormatter 格式化日志格式

func (*GormLogger) NowFunc

func (logger *GormLogger) NowFunc() time.Time

NowFunc 获取当前时间

func (*GormLogger) Print

func (logger *GormLogger) Print(values ...interface{})

Print 日志输出

type HttpConfig

type HttpConfig struct {
	ReadTime       int      `mapstructure:"read_time"`
	WriteTime      int      `mapstructure:"write_time"`
	MaxHeaderBytes int      `mapstructure:"max_header_bytes"`
	AllowIP        []string `mapstructure:"allow_ip"`
}

HttpConfig 是项目服务参数信息

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 列表

type SessionConfig

type SessionConfig struct {
	RedisServer   string `mapstructure:"redis_server"`
	RedisPassword string `mapstructure:"redis_password"`
}

SessionConfig 是 session 存储配置信息

type SwagConfig

type SwagConfig struct {
	Title    string `mapstructure:"title"`
	Describe string `mapstructure:"desc"`
	Host     string `mapstructure:"host"`
	BasePath string `mapstructure:"base_path"`
}

SwagConfig 是 swagger 文档配置信息

Jump to

Keyboard shortcuts

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