Documentation ¶
Index ¶
- Constants
- Variables
- func Close() error
- func ConfDo(trace *mylog.TraceContext, name string, commandName string, ...) (interface{}, error)
- func ConnFactory(name string) (redis.Conn, error)
- func Destroy()
- func Encode(data string) (string, error)
- func GetBoolConf(key string) bool
- func GetConfEnv() string
- func GetConfFile(fileName string) string
- func GetConfFilePath(fileName string) string
- func GetConfPath() string
- func GetDBPool(name string) (*sqlx.DB, error)
- func GetDurationConf(key string) time.Duration
- func GetFloat64Conf(key string) float64
- func GetGormPool(name string) (*gorm.DB, error)
- func GetIntConf(key string) int
- func GetLocalIPs() (ips []net.IP)
- func GetMd5Hash(text string) string
- func GetStringConf(key string) string
- func GetStringMapConf(key string) map[string]interface{}
- func GetStringMapStringConf(key string) map[string]string
- func GetStringSliceConf(key string) []string
- func GetTimeConf(key string) time.Time
- func InArrayString(s string, arr []string) bool
- func Init(configPath string) error
- func InitDBPool() error
- func InitModule(configPath string, modules []string) error
- func IsSetConf(key string) bool
- func LogDo(trace *mylog.TraceContext, c redis.Conn, commandName string, ...) (interface{}, error)
- func ParseConfPath(config string) error
- func ParseConfig(path string, fileName string, conf interface{}) (err error)
- func ParseLocalConfig(fileName string, st interface{}) error
- func SqlxLogExec(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string, args ...interface{}) (sql.Result, error)
- func SqlxLogGet(trace *mylog.TraceContext, sqlDB *sqlx.DB, dest interface{}, query string, ...) error
- func SqlxLogNamedExec(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string, arg interface{}) (sql.Result, error)
- func SqlxLogNamedQuery(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string, arg interface{}) (*sqlx.Rows, error)
- func SqlxLogQuery(trace *mylog.TraceContext, sqlDB *sqlx.DB, query string, args ...interface{}) (*sql.Rows, error)
- func SqlxLogSelect(trace *mylog.TraceContext, sqlDB *sqlx.DB, dest interface{}, query string, ...) error
- func SqlxLogTxExec(trace *mylog.TraceContext, tx *sqlx.Tx, query string, args ...interface{}) (sql.Result, error)
- type GormLogger
- type HttpConfig
- type HttpsConfig
- type LogConfig
- type MySQLConfig
- type MySQLMapConfig
- type ProxyConfig
- type RedisConfig
- type RedisMapConfig
Constants ¶
const (
DefaultConfEnvPath = "./configs/dev/"
)
默认读取配置文件路径
Variables ¶
var ( ConfProxy = new(ProxyConfig) //ConfMySQL = new(MySQLConfig) ConfMySQLMap = new(MySQLMapConfig) //ConfRedis = new(RedisConfig) ConfRedisMap = new(RedisMapConfig) ViperConfMap map[string]*viper.Viper )
配置信息全局变量
var ( ConfEnvPath string // 配置文件路径 ConfEnv string // 模式 )
配置文件全局变量
var ( DBMapPool map[string]*sqlx.DB GORMMapPool map[string]*gorm.DB DBDefaultPool *sqlx.DB GORMDefaultPool *gorm.DB )
全局变量
var ( TimeLocation *time.Location TimeFormat = "2006-01-02 15:04:05" DateFormat = "2006-01-02" LocalIP = net.ParseIP("127.0.0.1") )
全局变量
Functions ¶
func ConfDo ¶
func ConfDo(trace *mylog.TraceContext, name string, commandName string, args ...interface{}) (interface{}, error)
ConfDo 通过配置 执行redis
func GetStringMapConf ¶
GetStringMapConf 获取 string 为 key 的 map 类型信息
func GetStringMapStringConf ¶
GetStringMapStringConf 获取 map[string]string 类型配置信息
func GetStringSliceConf ¶
GetStringSliceConf 获取 []string 类型配置信息
func Init ¶
Init 公共初始化函数,支持两种方法设置配置文件
函数传入配置文件 Init("./configs/dev/") 如果配置文件为空,会重命令行读取 -config conf/dev/ 1. 加载配置(base、mysql、redis etc...) 2. 初始化日志
func InitModule ¶
InitModule 模块初始化 1. 加载 base 配置 2. 加载 mysql 配置 3. 加载 redis 配置 4. 初始化日志
func LogDo ¶
func LogDo(trace *mylog.TraceContext, c redis.Conn, commandName string, args ...interface{}) (interface{}, error)
LogDo 带有日志的 Do 方法
func ParseConfPath ¶
ParseConfPath 解析配置文件目录
配置文件必须放到一个文件夹中 如:config=conf/dev/base.json ConfEnvPath=conf/dev ConfEnv=dev 如:config=conf/base.json ConfEnvPath=conf ConfEnv=conf
func ParseConfig ¶
ParseConfig 解析本地配置文件
func ParseLocalConfig ¶
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 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 格式化日志格式
type HttpConfig ¶
type HttpConfig struct { HTTPPort int `mapstructure:"port"` ReadTime int `mapstructure:"read_time"` WriteTime int `mapstructure:"write_time"` MaxHeaderBytes int `mapstructure:"max_header_bytes"` }
HttpConfig 是项目服务参数信息
type HttpsConfig ¶
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 ProxyConfig ¶
type ProxyConfig 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"` *LogConfig `mapstructure:"log"` *HttpConfig `mapstructure:"http"` *HttpsConfig `mapstructure:"https"` }
BaseConfig 应用程序配置信息
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 列表