Documentation
¶
Overview ¶
Package util provides public goroutine-safe random function. The implementation is similar to grpc random functions. Additionally, the seed function is provided to be called from the outside, and the random functions are provided as a body's methods.
Index ¶
- Variables
- func Alias(src string) (name, alias string)
- func ArgRefererEscape(arg string) string
- func ArgRefererUnEscape(arg string) string
- func CalcTotalPage(total uint64, size int) uint32
- func FormatArgs(args []interface{}) []interface{}
- func FormatData(attributes map[string]interface{}, typeMap map[string]int8) (map[string]interface{}, error)
- func FormatDatas(datas []map[string]interface{}, typeMap map[string]int8) ([]map[string]interface{}, error)
- func GetDataByType(key string, value interface{}, typeMap map[string]int8) (interface{}, error)
- func GetIpFromAddr(addr net.Addr) string
- func GetLocalIP() string
- func GetMillisecond(sec int) time.Duration
- func GetRelation(dbType int, key string, v reflect.Value) (bool, bool, string)
- func IsRelation(dbType int, key string) int8
- func Namespace(src string) (namespace, name string)
- func OperatorMatch(key string, isElastic bool) (column, operator, subOperator, matchType, minShouldMatch string, boost float64, ...)
- func ParseConnFromAddress(addr *DBAddress) (err error)
- func ParseTarget(address string) (target, params string, paramsMap map[string]string, err error)
- func PathAndField(refer string) (string, string)
- func RemoveComments(key string) string
- type DBAddress
- type DBConnInfo
- type Order
- type SafeRand
Constants ¶
This section is empty.
Variables ¶
View Source
var ( DBConnMap = map[int]map[string]*DBConnInfo{} DBConnMapLock = new(sync.RWMutex) )
Functions ¶
func ArgRefererEscape ¶
ArgRefererEscape arg 参数如果包含引用符,可以用该函数转义。
func ArgRefererUnEscape ¶
ArgRefererUnEscape arg 参数如果包含引用符,可以用该函数反转义。
func CalcTotalPage ¶
CalcTotalPage 根据数据总数和每页大小计算总页数。
func FormatArgs ¶
func FormatArgs(args []interface{}) []interface{}
FormatArgs change args bytes to string
func FormatData ¶
func FormatData(attributes map[string]interface{}, typeMap map[string]int8) (map[string]interface{}, error)
FormatData 根据类型格式化数据
func FormatDatas ¶
func FormatDatas(datas []map[string]interface{}, typeMap map[string]int8) ([]map[string]interface{}, error)
FormatDatas 根据类型格式化数据
func GetDataByType ¶
GetDataByType 获取数据的真实类型
func GetIpFromAddr ¶
func GetRelation ¶
GetRelation 获取关系连接词
func OperatorMatch ¶
func OperatorMatch(key string, isElastic bool) (column, operator, subOperator, matchType, minShouldMatch string, boost float64, slop int)
OperatorMatch 匹配操作符
func ParseConnFromAddress ¶
ParseConnFromAddress 解析数据库网络信息
func ParseTarget ¶
ParseTarget address should be like: target?param1=value1¶m2=value2¶m3=value3 ...
Types ¶
type DBAddress ¶
type DBAddress struct {
Type int `json:"type,omitempty"` // 数据库类型 0-nil(仅执行插件) 1-elastic 2-mongo 3-redis 10-mysql 11-postgresql 12-clickhouse 13-oracle 14-DB2 15-sqlite
Version string `json:"version,omitempty"` // 数据库版本,比如elastic v6,v7
Network string `json:"network,omitempty"` // network TCP/UDP
Address string `json:"address,omitempty"` // address
Conn *DBConnInfo `json:"conn,omitempty"` // connect info
WriteTimeout int `json:"write_timeout,omitempty"` // 写超时(毫秒)
ReadTimeout int `json:"read_timeout,omitempty"` // 读超时(毫秒)
WarnTimeout int `json:"warn_timeout,omitempty"` // 告警超时(ms),如果请求耗时超过这个时间,就会打 warning 日志
OmitError int8 `json:"omit_error,omitempty"` // 是否忽略 error 日志,0-否 1-是
Debug int8 `json:"debug,omitempty"` // 是否开启 debug 日志,正常的数据库请求也会被打印到日志,0-否 1-是,会造成海量日志,慎重开启
}
type DBConnInfo ¶
type DBConnInfo struct {
Schema string `json:"schema,omitempty"` // schema
Target string `json:"target,omitempty"` // target
DB string `json:"db,omitempty"` // db name
Password string `json:"password,omitempty"` // password
Params string `json:"params,omitempty"` // params
DSN string `json:"dsn,omitempty"` // dsn
DSN2 string `json:"dsn2,omitempty"` // dsn2
DSN3 string `json:"dsn3,omitempty"` // dsn3
}
Click to show internal directories.
Click to hide internal directories.