util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 17 Imported by: 21

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

Constants

This section is empty.

Variables

View Source
var (
	DBConnMap     = map[int]map[string]*DBConnInfo{}
	DBConnMapLock = new(sync.RWMutex)
)

Functions

func Alias

func Alias(src string) (name, alias string)

Alias 别名

func ArgRefererEscape

func ArgRefererEscape(arg string) string

ArgRefererEscape arg 参数如果包含引用符,可以用该函数转义。

func ArgRefererUnEscape

func ArgRefererUnEscape(arg string) string

ArgRefererUnEscape arg 参数如果包含引用符,可以用该函数反转义。

func CalcTotalPage

func CalcTotalPage(total uint64, size int) uint32

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

func GetDataByType(key string, value interface{}, typeMap map[string]int8) (interface{}, error)

GetDataByType 获取数据的真实类型

func GetIpFromAddr

func GetIpFromAddr(addr net.Addr) string

func GetLocalIP

func GetLocalIP() string

GetLocalIP 获取本机 ip 地址

func GetMillisecond

func GetMillisecond(sec int) time.Duration

GetMillisecond 返回毫秒 time.Duration

func GetRelation

func GetRelation(dbType int, key string, v reflect.Value) (bool, bool, string)

GetRelation 获取关系连接词

func IsRelation

func IsRelation(dbType int, key string) int8

IsRelation 是否关系连接词

func Namespace

func Namespace(src string) (namespace, name string)

Namespace 命名空间

func OperatorMatch

func OperatorMatch(key string, isElastic bool) (column, operator,
	subOperator, matchType, minShouldMatch string, boost float64, slop int)

OperatorMatch 匹配操作符

func ParseConnFromAddress

func ParseConnFromAddress(addr *DBAddress) (err error)

ParseConnFromAddress 解析数据库网络信息

func ParseTarget

func ParseTarget(address string) (target, params string, paramsMap map[string]string, err error)

ParseTarget address should be like: target?param1=value1&param2=value2&param3=value3 ...

func PathAndField

func PathAndField(refer string) (string, string)

PathAndField 获取路径和字段

func RemoveComments

func RemoveComments(key string) string

RemoveComments 去掉注释

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
}

type Order

type Order struct {
	Field     string
	Ascending bool
}

Order 排序

func FormatOrders

func FormatOrders(orders []string) []*Order

FormatOrders 格式化排序

type SafeRand

type SafeRand struct {
	// contains filtered or unexported fields
}

func NewSafeRand

func NewSafeRand(seed int64) *SafeRand

func (*SafeRand) Intn

func (c *SafeRand) Intn(n int) int

Jump to

Keyboard shortcuts

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