mybase

package module
v0.0.25 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2024 License: BSD-2-Clause Imports: 40 Imported by: 0

README

mybase

go基础库,把一些常用的方法或者是类,封装一下,方便其他项目调用。

  1. events 模拟node中的事件分发监听机制。
  2. net2 封装了TCP socket和websocket。项目拿来直接写业务逻辑,不用再去写socket的逻辑了。
  3. report 封装了版署实名请求和游戏上报
  4. 钉钉通知 一键使用钉钉通知,监听服务器错误日志
  5. 日志 由于日志中使用了chan。所以写完日志需要sleep等待一下(仅限测试)。

Documentation

Index

Constants

View Source
const (
	//redis 缓存信息的版本号,从数据库第一次取出来放进去是0
	VerInRedis = "ver_in_redis"

	//redis写入标志位 请求写入的时候 incrBy 1,如果返回1表示可以写入,大于1表示已有其他服务器正在写入,要么等待要么直接返回
	WritingInRedis = "writing_in_redis"
)
View Source
const (
	GinKeyDingDSecret = "gin_key_dingd_secret"
	DingDingUrl       = "https://oapi.dingtalk.com/robot/send?access_token="
)
View Source
const (
	GinKeyRedisLockKey = "gin_key_redis_lock_key" //string
	GinKeyRedisLockCnt = "gin_key_redis_lock_cnt" //int64
	GinKeyRedisLockTtl = "gin_key_redis_lock_ttl" //time.Duration
)
View Source
const (
	TimeFmt             = "2006/01/02 15:04:05.000" //毫秒保留3位有效数字
	TimeFmtDB           = "2006-01-02 15:04:05"     //写入数据库用的时间
	TimeFmtDB2          = "2006-01-02 15:04:05.000" //写入数据库用的时间 带上毫秒
	TimeFmtSeq          = "20060102150405"          //yyyyMMddHHmmss
	TimeFmtSeqHW        = "20060102150405000"
	DateFmtDB           = "2006-01-02" //写入数据库用的日期
	AesKey       string = "Aabc#123admin@12"
)
View Source
const (
	WGSuccess                  = iota //成功
	WGFail                            //请求失败
	WGErrorParam                      //参数非法
	WGErrorTime                       //时间戳非法
	WGErrorSign                       //签名错误
	WGErrorTip                        //提示msg信息
	WGErrorNeedLogin                  //需要重新登录
	WGErrorParse                      //json格式解析出错
	WGErrorNet                        //网络异常
	WGErrorDataBase                   //数据库操作失败
	WGErrorNoReg                      //尚未注册
	WGIPForbidden                     //该IP禁止访问
	WGErrorBusy                       //客户端提示请勿频繁操作 12
	WGErrorRegistered                 //已注册 13
	WGErrorNoImp                      //未实现 14
	WGErrorEmpty                      //当前库存为0
	WGNeedKefu                        //请求可能成功,但是需要客服进一步处理
	WGSuccessWithTipDeprecated        //成功处理,但是还需要异步回调通知。客户端可以先给提示。--该提示有被刷风险,尽量避免
	WGLimitToday                      //今日次数已达上限 18
	WGIdSuspend                       //账号封禁 19
	WGErrConf                         //配置异常 20
	WGErrStat                         //状态异常 21
	WGErrNoChance                     //次数不足 22
	WGErrServer                       //服务器异常 23
	WGErrData                         //数据解析失败 24
	WGErrBuyed                        //您已买过此类商品 25
	WGServerBusy                      //服务器繁忙 26
	WGErrorExtBegin            = 1000 //扩展错误码起始
)

Http 返回值中的code状态码

View Source
const (
	Reset       = "\033[0m"
	Red         = "\033[31m"
	Green       = "\033[32m"
	Yellow      = "\033[33m"
	Blue        = "\033[34m"
	Magenta     = "\033[35m"
	Cyan        = "\033[36m"
	White       = "\033[37m"
	BlueBold    = "\033[34;1m"
	MagentaBold = "\033[35;1m"
	RedBold     = "\033[31;1m"
	YellowBold  = "\033[33;1m"

	Custom     = logrus.Level(1000)
	Custom2    = logrus.Level(1001)
	ChangeFile = 2000
)

Colors

View Source
const TimeFmtLog = "2006/01/02 15:04:05.000" //毫秒保留3位有效数字
View Source
const TimeFmtLog2 = "15:04:05.000" //毫秒保留3位有效数字

Variables

View Source
var (
	ErrNoDB    = errors.New("db not init")
	ErrNoImp   = errors.New("no implementation")
	ErrNoRedis = errors.New("redis not init")

	ErrParse     = errors.New("parse error")
	ErrNoData    = errors.New("database/redis no data")
	ErrData      = errors.New("redis data error")
	ErrDataOld   = errors.New("data not new,need reget")    //你的数据不是最新的请重新获取
	ErrIsWriting = errors.New("data is writing by someone") //这个数据正在被某个服务器改写
	ErrAbort     = errors.New("abort")
	ErrTryMax    = errors.New("try max limit") //重试次数已达上限
	ErrOccur     = errors.New("err occur")     //发生了一次错误
	ErrInner     = errors.New("inner error")
	ErrThird     = errors.New("third platform error")
	ErrParam     = errors.New("param error")
)
View Source
var (
	SmAppId     = ""
	SmBizId     = ""
	SmAppSecret = ""
	SmlUrl      = ""
)
View Source
var SqlRegExp *regexp.Regexp

Functions

func AESEncrypt

func AESEncrypt(plantText, key []byte) ([]byte, error)

func AESGCMDecrypter

func AESGCMDecrypter(key string, cipherbyte []byte) (plaintext string, err error)

AES CBC 解码 key:解密key ciphertext:加密返回的串 plaintext:解密后的字符串

func AESGCMEncrypt

func AESGCMEncrypt(key, plaintext string) (cipherbyte []byte, err error)

func Abort

func Abort(ctx *gin.Context, code int32)

func AbortEx

func AbortEx(ctx *gin.Context, code int32, data any, msg string)

func AbortWithData

func AbortWithData(ctx *gin.Context, code int32, data any)

func AbortWithMsg

func AbortWithMsg(ctx *gin.Context, code int32, msg string)

func AddHook

func AddHook(hook logrus.Hook)

func AesDecrypt

func AesDecrypt(crypted, key, iv []byte) ([]byte, error)

func BuildResult

func BuildResult(w http.ResponseWriter, r *http.Request, code int32, msg string, data any)

构造http返回结果

func BuildResult1

func BuildResult1(w http.ResponseWriter, r *http.Request, code int32)

func BuildResult2

func BuildResult2(w http.ResponseWriter, r *http.Request, code int32, msg string)

func BuildResultEx

func BuildResultEx(w http.ResponseWriter, r *http.Request, result string)

func C

func C(p []byte)

自定义打印,兼容其他依赖

func CheckDay

func CheckDay()

func CheckDayForLogBig

func CheckDayForLogBig()

func CheckHttpHeader

func CheckHttpHeader(w http.ResponseWriter, r *http.Request, isProduct bool, preFix, subFix string) (bool, string)

func CheckHttpOptions

func CheckHttpOptions(w http.ResponseWriter, r *http.Request) bool

func CompileVer

func CompileVer(ver1, ver2 string) int

func ConvertVersion

func ConvertVersion(version string) int64

func CrossMidW

func CrossMidW(ctx *gin.Context)

func D

func D(format string, args ...any)

func Decode

func Decode(input, outputPtr any) error

* map[string]any ->数据结构 数据结构 -> map[string]any

@param input []map[string]any 或者 map[string]any 或者 结构 @param output 结构指针 或者 map指针

@return nil无错误

func DecodeEx

func DecodeEx(input, outputPtr any, weakly bool) error

* @outputPtr 需要指针类型

func DecodeRedis

func DecodeRedis(input, outputPtr any) error

* map[string]any ->结构指针 相比于Decode;DecodeRedis会自动转换需要的数据类型;

比如string转换成int。当然前提是该数据类型支持转换

func DingWarn

func DingWarn(dingMsg *ReqDingMsg, secret string) (bool, string)

func DingWarnMidW

func DingWarnMidW(ctx *gin.Context)

func E

func E(format string, args ...any)

func EarthDistance

func EarthDistance(lat1, lng1, lat2, lng2 float64) float64

func EasyGet

func EasyGet(ctx *gin.Context, key string, output any) bool

func EasyGetMap

func EasyGetMap(dict *sync.Map, key any, output any) bool

func GetDingWarnMidW

func GetDingWarnMidW(secret string) gin.HandlerFunc

func GetFullPath

func GetFullPath(filename string) (string, error)

func GetRandSeed

func GetRandSeed() int64

func GetRandom

func GetRandom(maxValue int) int

maxValue > 0

func GetRandomI32

func GetRandomI32(maxValue int) int32

func GetRandomString

func GetRandomString(l int) string

func GetRedisLockCustomMidW

func GetRedisLockCustomMidW(f CustomKey, limit int64, ttl time.Duration) gin.HandlerFunc

互斥请求。防止多线程请求

func GetRedisLockMidW

func GetRedisLockMidW(key string, limit int64, ttl time.Duration) gin.HandlerFunc

互斥请求。防止多线程请求

func GetSafeUserInput

func GetSafeUserInput(input string) string

过滤 单引号 ,双引号,斜杠

func GetTodayMidnight

func GetTodayMidnight() time.Time

获取到今天0点的time.Time

func GetTodayMidnightEx

func GetTodayMidnightEx(theTime *time.Time) time.Time

获取到指定时间的0点的time.Time

func GetTomorrowMidnight

func GetTomorrowMidnight() time.Time

明天0点

func HMACSHA1

func HMACSHA1(text, key []byte) string

func HMACSHA1Base64

func HMACSHA1Base64(text, key []byte) string

func HMACSHA1Buf

func HMACSHA1Buf(text, key []byte) []byte

func HMACSHA256

func HMACSHA256(text, key []byte) string

func HMACSHA256Buf

func HMACSHA256Buf(text, key []byte) []byte

func HttpGet

func HttpGet(host, api string, param map[string]any, preFix, subFix string) (string, error)

func HttpGetEx

func HttpGetEx(host, api string, param map[string]any, preFix, subFix string, needSign bool) (string, error)

func HttpGetUrl

func HttpGetUrl(httpUrl string, param map[string]any, preFix, subFix string, needSign bool) (string, error)

func HttpGetUrlEx

func HttpGetUrlEx(httpUrl string, param, customHead map[string]any, preFix, subFix string, needSign bool) (string, error)

func HttpGetUrlNoSign

func HttpGetUrlNoSign(url string, param map[string]any) (string, error)

func HttpGetUrlValues

func HttpGetUrlValues(httpUrl string, query url.Values, customHead map[string]any, preFix, subFix string, needSign bool) (string, error)

func HttpPost

func HttpPost(strURL, body string, heads map[string]any) (string, error)

直接调用这个HttpPost 需要指定heads["Content-Type"]

func HttpPostForm

func HttpPostForm(strURL string, params, heads map[string]any) (string, error)

func HttpPostFormWithQuery

func HttpPostFormWithQuery(strURL string, params, heads map[string]any, query url.Values) (string, error)

func HttpPostFormWithQuery2

func HttpPostFormWithQuery2(strURL string, params url.Values, heads map[string]any, query url.Values) (string, error)

func HttpPostJson

func HttpPostJson(strURL string, params, heads map[string]any) (string, error)

func HttpPostJsonString

func HttpPostJsonString(strURL, bodyStr string, heads map[string]any) (string, error)

func HttpPostWithQuery

func HttpPostWithQuery(strURL, body string, heads map[string]any, query url.Values) (string, error)

直接调用这个HttpPost 需要指定heads["Content-Type"]

func I

func I(format string, args ...any)

func InitGinMidW

func InitGinMidW(wall HelpRedisFirewall)

func InitLogBigFile

func InitLogBigFile(isProd bool, dir, prefix string, limitSize int64, limitDay time.Duration) error

func InitLogModule

func InitLogModule(dir, fileName string, day int, isInProduct bool, debugLv logrus.Level, ctx context.Context) error

func InitNoFile

func InitNoFile()

func InitReport added in v0.0.4

func InitReport(appId, bizId, appSecret, url string)

func LoadCfg

func LoadCfg(filename string, cfg any) error

func LogBig

func LogBig(format string, args ...any)

内部不提供换行,需要自己换行。

func MD5

func MD5(text string) string

MD5 生成32位MD5,小写

func OnDebugHttpReq

func OnDebugHttpReq()

func P

func P(format string, args ...any)

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PostReportData added in v0.0.4

func PostReportData(data *GovReportData)

func RandInt

func RandInt(minValue, maxValue int) int

区间:[minValue,maxValue)

func RedisLockMidW

func RedisLockMidW(ctx *gin.Context)

互斥请求。防止多线程请求。请求完毕后会解锁。 @注意:如果是防止暴力破解的话,需要在那个具体的业务上加锁。

func SameTransfer

func SameTransfer(input, outputPtr any)

* outputPtr 如果是 切片int数组,建议传int64

func SameTypeAdd

func SameTypeAdd(dest, src any)

* 同类型指针 简单数值相加。目前仅支持整数 int64 及以内。

func SendReport added in v0.0.4

func SendReport()

func SortParam

func SortParam(param map[string]any) string

func T

func T(format string, args ...any)

用于追踪定位

func UrlEncode

func UrlEncode(param string) string

func W

func W(format string, args ...any)

func WrapSql

func WrapSql(query string, args ...any) string

func Xor

func Xor(buf []byte, key string) []byte

Types

type At

type At struct {
	AtMobiles []string `json:"atMobiles"`
	IsAtAll   bool     `json:"isAtAll"`
}

type AtomicSet

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

func (*AtomicSet) Contain

func (a *AtomicSet) Contain(val any) bool

func (*AtomicSet) Insert

func (a *AtomicSet) Insert(val any)

func (*AtomicSet) Len

func (a *AtomicSet) Len() int

func (*AtomicSet) Next

func (a *AtomicSet) Next() (any, bool)

func (*AtomicSet) Random

func (a *AtomicSet) Random() (any, bool)

func (*AtomicSet) Range

func (a *AtomicSet) Range(cb func(val any) bool)

func (*AtomicSet) Remove

func (a *AtomicSet) Remove(val any)

type CustomKey

type CustomKey func(ctx *gin.Context) string

type DBMgrBase

type DBMgrBase struct {
	DbInst    *sql.DB
	RedisInst *redis.Client
	// contains filtered or unexported fields
}

func (*DBMgrBase) CallExec

func (d *DBMgrBase) CallExec(query string, args ...interface{}) (int64, error)

执行存储过程或者多个sql语句

func (*DBMgrBase) CallExecNoStmt

func (d *DBMgrBase) CallExecNoStmt(rawSql string, insert bool) (int64, error)

执行存储过程或者多个sql语句 @insert 是否需要返回最后的插入自增ID

func (*DBMgrBase) CallExecNoStmtWithLog

func (d *DBMgrBase) CallExecNoStmtWithLog(log bool, rawSql string, insert bool) (int64, error)

@insert 是否需要返回最后的插入自增ID

func (*DBMgrBase) CallQuery

func (d *DBMgrBase) CallQuery(v interface{}, query string, args ...interface{}) error

* @param v 必须是指针类型 *Struct1{}

func (*DBMgrBase) CallQueryResultSets

func (d *DBMgrBase) CallQueryResultSets(v []interface{}, query string, args ...interface{}) error

* 存储过程,返回多个数据表的信息,每个表信息需要单独存放。

多张表返回,每张表含有多行数据 @v 存储数据结构指针,每个位置对应了存储过程返回的指定位置的表结构信息 是一个二维数组结构指针 类似 *[*[]Struct1,*[]Struct2,*[]Struct3...]

如果只需要取第一张表的数据,可以直接调用CallQuery或CallQuerys

func (*DBMgrBase) CallQueryResultSetsOnlyFirst

func (d *DBMgrBase) CallQueryResultSetsOnlyFirst(v []interface{}, query string, args ...interface{}) error

多张表返回,每张表只取一行数据 @v 是一个数组结构指针 类似 *[*Struct1,*Struct2,*Struct3...]

func (*DBMgrBase) CallQueryWithLog

func (d *DBMgrBase) CallQueryWithLog(v interface{}, query string, args ...interface{}) error

打印一下日志,适用于重要的过程调用。

func (*DBMgrBase) CallQuerys

func (d *DBMgrBase) CallQuerys(v interface{}, query string, args ...interface{}) error

* @param v 必须是指针类型 //*[]Struct1{}

func (*DBMgrBase) CheckDBConnect

func (d *DBMgrBase) CheckDBConnect() error

func (*DBMgrBase) CheckDBConnectEx

func (d *DBMgrBase) CheckDBConnectEx(withRedis bool) error

func (*DBMgrBase) GetCnt

func (d *DBMgrBase) GetCnt(query string, args ...any) int64

func (*DBMgrBase) GetCntEx

func (d *DBMgrBase) GetCntEx(query string, args ...any) (int64, bool)

func (*DBMgrBase) GetSum

func (d *DBMgrBase) GetSum(query string, args ...any) int64

func (*DBMgrBase) GetSumFloat64

func (d *DBMgrBase) GetSumFloat64(query string, args ...any) float64

func (*DBMgrBase) Insert

func (d *DBMgrBase) Insert(query string, args ...interface{}) (int64, error)

Insert 通用方法

func (*DBMgrBase) InsertEx

func (d *DBMgrBase) InsertEx(query string, args ...interface{}) (int64, error, bool)

func (*DBMgrBase) InsertExWithLastId

func (d *DBMgrBase) InsertExWithLastId(lastId bool, query string, args ...interface{}) (int64, error, bool)

func (*DBMgrBase) InsertExWithLastIdEx

func (d *DBMgrBase) InsertExWithLastIdEx(log, lastId bool, query string, args ...interface{}) (int64, error, bool)

func (*DBMgrBase) LoadTable

func (d *DBMgrBase) LoadTable(query string, args ...any) ([]map[string]any, error)

读取单个数据库表到 []map[string]any 中

func (*DBMgrBase) LoadTableEx

func (d *DBMgrBase) LoadTableEx(query string, args ...any) ([][]map[string]any, error)

读取多个数据库表到 [][]map[string]any 中

func (*DBMgrBase) RedisCheckFireWall

func (d *DBMgrBase) RedisCheckFireWall(key string, limit int64, ttl time.Duration) bool

* 防刷,防止暴力破解

func (*DBMgrBase) RedisDel

func (d *DBMgrBase) RedisDel(key string) bool

func (*DBMgrBase) RedisExists

func (d *DBMgrBase) RedisExists(key string) bool

func (*DBMgrBase) RedisExpire

func (d *DBMgrBase) RedisExpire(key string, duration time.Duration)

* 设置过期时间

func (*DBMgrBase) RedisExpireAt

func (d *DBMgrBase) RedisExpireAt(key string, tm time.Time)

func (*DBMgrBase) RedisGet

func (d *DBMgrBase) RedisGet(key string) (string, error)

func (*DBMgrBase) RedisHGetAll

func (d *DBMgrBase) RedisHGetAll(key string, dataPtr interface{}) error

* 正常读取redis的数据,不管是否有其他服务器正在写入

func (*DBMgrBase) RedisHGetAllEx

func (d *DBMgrBase) RedisHGetAllEx(key string, dataPtr interface{}) error

* 正常读取redis的数据,如果有其他服务器正在写入,那么直接返回错误

func (*DBMgrBase) RedisHGetAllExLoop

func (d *DBMgrBase) RedisHGetAllExLoop(key string, dataPtr interface{}, tryCnt int, force bool) error

* 正常读取redis的数据,如果有其他服务器正在写入,那么等待写完毕,获取最新的数据 @tryCnt 重试次数,如果为-1表示永远等待

func (*DBMgrBase) RedisHIncrBy

func (d *DBMgrBase) RedisHIncrBy(key, field string, incr int64) (int64, error)

* 不存在的key或者field,redis中默认存0

func (*DBMgrBase) RedisHIncrByFlagAdd

func (d *DBMgrBase) RedisHIncrByFlagAdd(key string) (int64, error)

* 多个服务器分布式,读取redis中的标志位

func (*DBMgrBase) RedisHIncrByFlagCheck

func (d *DBMgrBase) RedisHIncrByFlagCheck(key string) (int64, error)

func (*DBMgrBase) RedisHIncrByFlagRelease

func (d *DBMgrBase) RedisHIncrByFlagRelease(key string) (int64, error)

func (*DBMgrBase) RedisHIncrByGetVer

func (d *DBMgrBase) RedisHIncrByGetVer(key string) (int64, error)

func (*DBMgrBase) RedisHMSet

func (d *DBMgrBase) RedisHMSet(key string, data interface{}, expire time.Duration) error

* 正常写入redis的数据,不管是否有其他服务器正在写入

@注意 谨慎使用该函数,该函数会导致之前的缓存数据被改写!!! @expire 单位秒,传入负数表示永不过期或者不想改变原本的有效时间

func (*DBMgrBase) RedisHMSetEx

func (d *DBMgrBase) RedisHMSetEx(key string, data interface{}, ver int64, ignoreVer bool, expire time.Duration) error

* 正常写入redis的数据,如果其他服务器正在写入,那么直接返回错误,如果缓存的信息比本地版本高也返回错误

func (*DBMgrBase) RedisHMSetExLoop

func (d *DBMgrBase) RedisHMSetExLoop(key string, dataPtr interface{}, ver int64, expire time.Duration,
	hook DealWithConflict, tryCnt int) error

* 正常写入redis的数据,如果其他服务器正在写入或者缓存中的信息版本比较高,那么我们等待写完毕把他取出来

@dataPtr 需要数据结构指针 @tryCnt 重试次数 -1表示永远尝试直到成功为止

func (*DBMgrBase) RedisIncrBy

func (d *DBMgrBase) RedisIncrBy(key string, incr int64) (int64, error)

func (*DBMgrBase) RedisIncrByFlagAdd

func (d *DBMgrBase) RedisIncrByFlagAdd(key string) (int64, error)

* 多个服务器分布式,读取redis中的标志位

func (*DBMgrBase) RedisIncrByFlagCheck

func (d *DBMgrBase) RedisIncrByFlagCheck(key string) (int64, error)

func (*DBMgrBase) RedisIncrByFlagRelease

func (d *DBMgrBase) RedisIncrByFlagRelease(key string) (int64, error)

func (*DBMgrBase) RedisKeys deprecated

func (d *DBMgrBase) RedisKeys(pattern string) ([]string, error)

Deprecated: 当redis中key较多的时候,会导致redis阻塞 建议使用 RedisScan

func (*DBMgrBase) RedisPersist

func (d *DBMgrBase) RedisPersist(key string)

func (*DBMgrBase) RedisSAdd

func (d *DBMgrBase) RedisSAdd(key string, members ...interface{}) error

func (*DBMgrBase) RedisSCard

func (d *DBMgrBase) RedisSCard(key string) int64

func (*DBMgrBase) RedisSMembers

func (d *DBMgrBase) RedisSMembers(key string) ([]string, error)

func (*DBMgrBase) RedisSRem

func (d *DBMgrBase) RedisSRem(key string, members ...interface{}) error

func (*DBMgrBase) RedisScan

func (d *DBMgrBase) RedisScan(pattern string, count int64) (keys []string, err error)

遍历key,每次遍历count个key

func (*DBMgrBase) RedisScanLimit added in v0.0.5

func (d *DBMgrBase) RedisScanLimit(pattern string, count int64, limit int) (keys []string, err error)

func (*DBMgrBase) RedisScanWithCount

func (d *DBMgrBase) RedisScanWithCount(pattern string, cursorStart uint64, count int64) (keys []string, cursor uint64, err error)

func (*DBMgrBase) RedisSet

func (d *DBMgrBase) RedisSet(key string, value interface{}) (bool, error)

func (*DBMgrBase) RedisSetEx

func (d *DBMgrBase) RedisSetEx(key string, value interface{}, expiration time.Duration) (bool, error)

* @expiration -1 永不失效

func (*DBMgrBase) RedisTTL

func (d *DBMgrBase) RedisTTL(key string) (time.Duration, error)

* @time.Duration -1表示永不过期,-2表示已经过期,大于0表示还有X秒过期。

func (*DBMgrBase) SelectObject

func (d *DBMgrBase) SelectObject(v any, query string, args ...any) error

the v must be a pointer to a map or struct.

func (*DBMgrBase) SelectObjectNoWarn

func (d *DBMgrBase) SelectObjectNoWarn(v any, query string, args ...any) error

func (*DBMgrBase) SelectObjectsEx

func (d *DBMgrBase) SelectObjectsEx(v any, query string, args ...any) error

* 跟SelectObject比,这个SelectObjectsEx是返回一个数组的。

@param v 必须是存放map或是struct的数组的指针.

func (*DBMgrBase) SelectObjectsEx2

func (d *DBMgrBase) SelectObjectsEx2(logWarn bool, v any, query string, args ...interface{}) error

func (*DBMgrBase) SelectObjectsExNoWarn

func (d *DBMgrBase) SelectObjectsExNoWarn(v any, query string, args ...any) error

func (*DBMgrBase) Update

func (d *DBMgrBase) Update(query string, args ...interface{}) bool

func (*DBMgrBase) Update2 added in v0.0.17

func (d *DBMgrBase) Update2(logWarn bool, query string, args ...interface{}) int64

通用的update方法

func (*DBMgrBase) UpdateNoWarn

func (d *DBMgrBase) UpdateNoWarn(query string, args ...interface{}) bool

type DealWithConflict

type DealWithConflict func(oldPtr, newPtr interface{}) (interface{}, int64)

type GovReportData added in v0.0.4

type GovReportData struct {
	No    int    `json:"no"`           //编号
	Si    string `json:"si"`           //服务器内部用户ID
	Bt    int    `json:"bt"`           //0下线,1上线
	Ot    int64  `json:"ot"`           //时间戳,单位秒
	Ct    int    `json:"ct"`           //0已认证用户,2游客
	Di    string `json:"di,omitempty"` //设备唯一标识  ct=2传这个
	Pi    string `json:"pi,omitempty"` //用户唯一标识 ct=0传这个
	Debug bool   `json:"-"`
}

type GovReportDatas added in v0.0.4

type GovReportDatas struct {
	Collections []*GovReportData `json:"collections"`
}

type H

type H map[string]any

func NewData

func NewData() H

func (H) Get

func (e H) Get(key string, output any) bool

* @output 必须是跟存的类型保持一致,output必须是指针类型

func (H) GetBool

func (e H) GetBool(key string) (bool, bool)

func (H) GetFloat64

func (e H) GetFloat64(key string) (float64, bool)

func (H) GetH

func (e H) GetH(key string) (H, bool)

func (H) GetInt

func (e H) GetInt(key string) (int, bool)

func (H) GetInt32

func (e H) GetInt32(key string) (ret int32, ok bool)

func (H) GetInt64

func (e H) GetInt64(key string) (ret int64, ok bool)

func (H) GetInterface

func (e H) GetInterface(key string) (any, bool)

func (H) GetString

func (e H) GetString(key string) (string, bool)

func (H) GetUInt64

func (e H) GetUInt64(key string) (uint64, bool)

func (H) Set

func (e H) Set(key string, val any)

type HelpRedisFirewall

type HelpRedisFirewall interface {
	RedisCheckFireWall(key string, limit int64, duration time.Duration) bool
	RedisDel(key string) bool
}

type HttpResult

type HttpResult struct {
	Code int    `json:"code"` //状态码
	Msg  string `json:"msg"`  //信息
	Data any    `json:"data"` //数据结构
}

type LogWriter added in v0.0.8

type LogWriter struct {
}

func (*LogWriter) Write added in v0.0.8

func (w *LogWriter) Write(p []byte) (n int, err error)

type LogWriterError added in v0.0.10

type LogWriterError struct {
}

func (*LogWriterError) Write added in v0.0.10

func (w *LogWriterError) Write(p []byte) (n int, err error)

type MsgDing

type MsgDing struct {
	Title string `json:"title"`
	Text  string `json:"text"`
}

type PrintHook

type PrintHook struct {
}

func (*PrintHook) Fire

func (imp *PrintHook) Fire(entry *logrus.Entry) error

打印

func (*PrintHook) Levels

func (imp *PrintHook) Levels() []logrus.Level

过滤等级

type ReqDingMsg

type ReqDingMsg struct {
	Token    string `json:"token" form:"token"`
	MsgTitle string `json:"title" form:"title"`
	MsgDing  string `json:"msg" form:"msg"`
	Phones   string `json:"phones" form:"phones"`
	All      int32  `json:"all" form:"all"`
}

type UsrCheckIn

type UsrCheckIn struct {
	Day int8 `json:"day"` //签到第几天。
}

type UsrInRedis

type UsrInRedis struct {
	ProtoData      string `json:"proto_data"`       //base64加密过的数据
	ProtoDataOrgin []byte `json:"proto_data_orgin"` //proto 原始数据
	VerInRedis     int64  `json:"ver_in_redis"`     //redis中的版本,0表示刚从数据库写入,每次改写redis中的数据的时候都必须判断版本是否大于这个值
	FlagSyncDB     int32  `json:"flag_sync_db"`     //是否已经将数据同步到数据库 0标识已经同步过,1标识尚未同步

}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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