lib

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 License: Apache-2.0 Imports: 27 Imported by: 8

Documentation

Index

Constants

View Source
const (
	SRTagUndefind      = "_undef"
	SRTagMySqlFailed   = "_com_mysql_failure"
	SRTagRedisFailed   = "_com_redis_failure"
	SRTagMySqlSuccess  = "_com_mysql_success"
	SRTagRedisSuccess  = "_com_redis_success"
	SRTagThriftFailed  = "_com_thrift_failure"
	SRTagThriftSuccess = "_com_thrift_success"
	SRTagHTTPSuccess   = "_com_http_success"
	SRTagHTTPFailed    = "_com_http_failure"
	SRTagTCPFailed     = "_com_tcp_failure"
	SRTagRequestIn     = "_com_request_in"
	SRTagRequestOut    = "_com_request_out"
)

通用DLTag常量定义

Variables

View Source
var (
	ConfBase        *BaseConf
	DBMapPool       map[string]*sql.DB
	GORMMapPool     map[string]*gorm.DB
	DBDefaultPool   *sql.DB
	GORMDefaultPool *gorm.DB
	ConfRedis       *RedisConf
	ConfRedisMap    *RedisMapConf
	ViperConfMap    map[string]*viper.Viper
)

全局变量

View Source
var (
	TimeLocation *time.Location
	TimeFormat   = "2006-01-02 15:04:05"
	DateFormat   = "2006-01-02"
	LocalIP      = net.ParseIP("127.0.0.1")
)
View Source
var ConfEnv string //配置环境名 比如:dev prod test
View Source
var ConfEnvPath string //配置文件夹
View Source
var DefaultMysqlGormLogger = MysqlGormLogger{
	LogLevel:      logger.Info,
	SlowThreshold: 200 * time.Millisecond,
}

DefaultMysqlGormLogger 日志打印类型

Functions

func AddGetDataToUrl

func AddGetDataToUrl(urlString string, data url.Values) string

func CloseDB

func CloseDB() error

func CreateBizDLTag

func CreateBizDLTag(tagName string) string

CreateBizDLTag 生成业务srtag

func DBPoolLogQuery

func DBPoolLogQuery(trace *TraceContext, sqlDb *sql.DB, query string, args ...interface{}) (*sql.Rows, error)

func Destroy

func Destroy()

Destroy 公共销毁函数

func Encode

func Encode(data string) (string, error)

func GetBoolConf

func GetBoolConf(key string) bool

GetBoolConf 获取get配置信息

func GetConf

func GetConf(key string) interface{}

GetConf 获取get配置信息

func GetConfEnv

func GetConfEnv() string

GetConfEnv 获取配置环境名

func GetConfFilePath

func GetConfFilePath(fileName string) string

func GetConfPath

func GetConfPath(fileName string) string

func GetDBPool

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

func GetDurationConf

func GetDurationConf(key string) time.Duration

GetDurationConf 获取时间阶段长度

func GetFloat64Conf

func GetFloat64Conf(key string) float64

GetFloat64Conf 获取get配置信息

func GetGormPool

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

func GetIntConf

func GetIntConf(key string) int

GetIntConf 获取get配置信息

func GetLocalIPs

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

func GetMd5Hash

func GetMd5Hash(text string) string

func GetStringConf

func GetStringConf(key string) string

GetStringConf 获取get配置信息

func GetStringMapConf

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

GetStringMapConf 获取get配置信息

func GetStringMapStringConf

func GetStringMapStringConf(key string) map[string]string

GetStringMapStringConf 获取get配置信息

func GetStringSliceConf

func GetStringSliceConf(key string) []string

GetStringSliceConf 获取get配置信息

func GetTimeConf

func GetTimeConf(key string) time.Time

GetTimeConf 获取get配置信息

func GetTraceId

func GetTraceId() (traceId string)

func HttpGET

func HttpGET(trace *TraceContext, urlString string, urlParams url.Values, msTimeout int, header http.Header) (*http.Response, []byte, error)

func HttpJSON

func HttpJSON(trace *TraceContext, urlString string, jsonContent string, msTimeout int, header http.Header) (*http.Response, []byte, error)

func HttpPOST

func HttpPOST(trace *TraceContext, urlString string, urlParams url.Values, msTimeout int, header http.Header, contextType string) (*http.Response, []byte, error)

func InArrayString

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

func Init

func Init(configPath string) error

Init 公共初始化函数:支持两种方式设置配置文件 函数传入配置文件 Init("./conf/dev/") 如果配置文件为空,会从命令行中读取 -config conf/dev/

func InitBaseConf

func InitBaseConf(path string) error

func InitDBPool

func InitDBPool(path string) error

func InitModule

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

InitModule 模块初始化

func InitRedisConf

func InitRedisConf(path string) error

func InitViperConf

func InitViperConf() error

InitViperConf 初始化配置文件

func IsSetConf

func IsSetConf(key string) bool

IsSetConf 是否设置了key

func NewSpanId

func NewSpanId() string

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, conf interface{}) error

func ParseLocalConfig

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

ParseLocalConfig 本地解析文件

func ParseServerAddr

func ParseServerAddr(serverAddr string) (host, port string)

func RedisConfDo

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

RedisConfDo 通过配置 执行redis

func RedisConnFactory

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

func RedisLogDo

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

func SetGinTraceContext

func SetGinTraceContext(c *gin.Context, trace *TraceContext) error

func SetTraceContext

func SetTraceContext(ctx context.Context, trace *TraceContext) context.Context

func Substr

func Substr(str string, start int64, end int64) string

Substr 字符串的截取

Types

type BaseConf

type BaseConf struct {
	DebugMode    string    `mapstructure:"debug_mode"`
	TimeLocation string    `mapstructure:"time_location"`
	Log          LogConfig `mapstructure:"log"`
	Base         struct {
		DebugMode    string `mapstructure:"debug_mode"`
		TimeLocation string `mapstructure:"time_location"`
	} `mapstructure:"base"`
}

func GetBaseConf

func GetBaseConf() *BaseConf

GetBaseConf 获取基本配置信息

type LogConfConsoleWriter

type LogConfConsoleWriter struct {
	On    bool `mapstructure:"on"`
	Color bool `mapstructure:"color"`
}

type LogConfFileWriter

type LogConfFileWriter struct {
	On              bool   `mapstructure:"on"`
	LogPath         string `mapstructure:"log_path"`
	RotateLogPath   string `mapstructure:"rotate_log_path"`
	WfLogPath       string `mapstructure:"wf_log_path"`
	RotateWfLogPath string `mapstructure:"rotate_wf_log_path"`
}

type LogConfig

type LogConfig struct {
	Level      string               `mapstructure:"log_level"`
	FW         LogConfFileWriter    `mapstructure:"file_writer"`
	CW         LogConfConsoleWriter `mapstructure:"console_writer"`
	CallerSkip int                  `mapstructure:"caller_skip"`
}

type Logger

type Logger struct{}
var Log *Logger

func (*Logger) Close

func (l *Logger) Close()

func (*Logger) TagDebug

func (l *Logger) TagDebug(trace *TraceContext, srtag string, m map[string]interface{})

func (*Logger) TagError

func (l *Logger) TagError(trace *TraceContext, srtag string, m map[string]interface{})

func (*Logger) TagInfo

func (l *Logger) TagInfo(trace *TraceContext, srtag string, m map[string]interface{})

func (*Logger) TagTrace

func (l *Logger) TagTrace(trace *TraceContext, srtag string, m map[string]interface{})

func (*Logger) TagWarn

func (l *Logger) TagWarn(trace *TraceContext, srtag string, m map[string]interface{})

type MySQLConf

type MySQLConf struct {
	DriverName      string `mapstructure:"driver_name"`
	DataSourceName  string `mapstructure:"data_source_name"`
	MaxOpenConn     int    `mapstructure:"max_open_conn"`
	MaxIdleConn     int    `mapstructure:"max_idle_conn"`
	MaxConnLifeTime int    `mapstructure:"max_conn_life_time"`
}

type MysqlGormLogger

type MysqlGormLogger struct {
	LogLevel      logger.LogLevel
	SlowThreshold time.Duration
}

func (*MysqlGormLogger) Error

func (mgl *MysqlGormLogger) Error(ctx context.Context, message string, values ...interface{})

func (*MysqlGormLogger) Info

func (mgl *MysqlGormLogger) Info(ctx context.Context, message string, values ...interface{})

func (*MysqlGormLogger) LogMode

func (mgl *MysqlGormLogger) LogMode(logLevel logger.LogLevel) logger.Interface

func (*MysqlGormLogger) Trace

func (mgl *MysqlGormLogger) Trace(ctx context.Context, begin time.Time, fc func() (sql string, rowsAffected int64), err error)

func (*MysqlGormLogger) Warn

func (mgl *MysqlGormLogger) Warn(ctx context.Context, message string, values ...interface{})

type MysqlMapConf

type MysqlMapConf struct {
	List map[string]*MySQLConf `mapstructure:"list"`
}

type RedisConf

type RedisConf struct {
	ProxyList    []string `mapstructure:"proxy_list"`
	Password     string   `mapstructure:"password"`
	Db           int      `mapstructure:"db"`
	ConnTimeout  int      `mapstructure:"conn_timeout"`
	ReadTimeout  int      `mapstructure:"read_timeout"`
	WriteTimeout int      `mapstructure:"write_timeout"`
}

type RedisMapConf

type RedisMapConf struct {
	List map[string]*RedisConf `mapstructure:"list"`
}

type Trace

type Trace struct {
	TraceId     string
	SpanId      string
	Caller      string
	SrcMethod   string
	HintCode    int64
	HintContent string
}

type TraceContext

type TraceContext struct {
	Trace
	CSpanId string
}

func GetTraceContext

func GetTraceContext(ctx context.Context) *TraceContext

func NewTrace

func NewTrace() *TraceContext

Jump to

Keyboard shortcuts

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