Documentation ¶
Index ¶
- Variables
- func AddSlashes(str string) string
- func AesCBCDecrypt(str, key string) (string, error)
- func AesCBCEncrypt(str, key string) (string, error)
- func FileAppend(file, content string) (bool, error)
- func FileDel(file string) (bool, error)
- func FileDelAll(dir string) (bool, error)
- func FileExist(file string) bool
- func FileInfo(file string) (fs.FileInfo, error)
- func FileIsDir(file string) (bool, error)
- func FileMd5(file string) (string, error)
- func FileMkDir(dir string) (bool, error)
- func FileRead(file string) ([]byte, error)
- func FileReadDir(dir string) ([]string, error)
- func FileReadDirAll(dir string) ([]string, error)
- func FileReadLines(file string) (lines []string, err error)
- func FileReadPart(file string, offset, length int64) ([]byte, error)
- func FileWalkLines(file string, fn func(l string) error) (err error)
- func FileWrite(file, content string) (bool, error)
- func GetBinPath() (string, error)
- func GetHomeDir() (string, error)
- func HttpSrvRun(addr string, hdl http.Handler, onClose func())
- func InArray(needle any, haystack any) (isIn bool, err error)
- func InterfaceToFloat64(v any) (ret float64)
- func InterfaceToInt(v any) (ret int)
- func InterfaceToInt64(v any) (ret int64)
- func InterfaceToStr(v any) (ret string)
- func LocalIp() string
- func MongoPing(client *mongo.Client) error
- func NewMongoClient(dsn string) (*mongo.Client, error)
- func PKCS7Padding(ciphertext []byte, blockSize int) []byte
- func PKCS7UnPadding(origData []byte) []byte
- func RandInt(i int) int
- func RandRange(min, max int) int
- func Retry(attempt uint, sleep time.Duration, fn func() error) error
- func RsaGenKeys(bits int) (publicKey, privateKey []byte, err error)
- func ShellExec(cmdBin string, args ...string) (ret []string, err error)
- func ShellExecWalk(fn func(s string) error, cmdBin string, args ...string) error
- func StrAToFloat64(s string) (f float64, err error)
- func StrCamelToCase(s string) string
- func StrCaseToCamel(s string) string
- func StrCheckPass(pass, hash string) bool
- func StrEndWith(str, find string) bool
- func StrFileName(name string) (string, error)
- func StrHashPass(pass string) (string, error)
- func StrHexDecode(s string) ([]byte, error)
- func StrHexEncode(bs []byte) string
- func StrImplode(gap string, ss ...string) string
- func StrMd5(s string) string
- func StrNiceSize(sizeI int64) string
- func StrRandom(l int, c string) string
- func StrSha1(s string) string
- func StrSha256(s string) string
- func StrStartWith(str, find string) bool
- func StrSubZh(str string, start, end uint) string
- func StrTrim(s string) string
- func StripSlashes(str string) string
- func StripXSS(s string, isUGC bool) string
- func TimeDateFromStamp(ts int64) string
- func TimeDateToStamp(str string) (int64, error)
- func TimeFormStamp(ts int64) string
- func TimeLocationBJ() *time.Location
- func TimeNice(t time.Time) string
- func TimeNowAsSN() string
- func TimeNowDateNice() string
- func TimeNowNice() string
- func TimeNowTimeNice() string
- func TimeToStamp(str string) (int64, error)
- func VarDump(v ...any)
- type AmqpClient
- type MemCache
- func (s *MemCache) Clear()
- func (s *MemCache) Del(k string)
- func (s *MemCache) ExpireAt(k string) int64
- func (s *MemCache) GC(td time.Duration, num uint64)
- func (s *MemCache) Get(k string) (any, error)
- func (s *MemCache) GetOrSingleDo(k string, fn func(k string, mc *MemCache) (any, error)) (any, error)
- func (s *MemCache) Set(k string, v any, exp int64)
- func (s *MemCache) SetExpire(k string, exp int64) error
- func (s *MemCache) SetNX(k string, v any, exp int64) error
- type MongoCollection
- func (mc *MongoCollection) AggregateWalk(ctx context.Context, fn func(v bson.M) error, pipeline mongo.Pipeline, ...) error
- func (mc *MongoCollection) BulkWrite(ctx context.Context, models []mongo.WriteModel, ...) (res *mongo.BulkWriteResult, err error)
- func (mc *MongoCollection) CountDocuments(ctx context.Context, where any, opts ...*options.CountOptions) (int64, error)
- func (mc *MongoCollection) CursorAll(ctx context.Context, cursor *mongo.Cursor) ([]bson.M, error)
- func (mc *MongoCollection) CursorWalk(ctx context.Context, fn func(v bson.M) error, cursor *mongo.Cursor) error
- func (mc *MongoCollection) DeleteMany(ctx context.Context, where any, opts ...*options.DeleteOptions) (num int64, err error)
- func (mc *MongoCollection) DeleteOne(ctx context.Context, where any, opts ...*options.DeleteOptions) (num int64, err error)
- func (mc *MongoCollection) Distinct(ctx context.Context, name string, where any, opts ...*options.DistinctOptions) ([]any, error)
- func (mc *MongoCollection) Drop(ctx context.Context) (err error)
- func (mc *MongoCollection) Find(ctx context.Context, where any, opts ...*options.FindOptions) ([]bson.M, error)
- func (mc *MongoCollection) FindOne(ctx context.Context, where any, opts ...*options.FindOneOptions) (bson.M, error)
- func (mc *MongoCollection) FindOneAndDelete(ctx context.Context, where any, opts ...*options.FindOneAndDeleteOptions) (res bson.M, err error)
- func (mc *MongoCollection) FindOneAndReplace(ctx context.Context, where, set any, opts ...*options.FindOneAndReplaceOptions) (res bson.M, err error)
- func (mc *MongoCollection) FindOneAndUpdate(ctx context.Context, where, set any, opts ...*options.FindOneAndUpdateOptions) (res bson.M, err error)
- func (mc *MongoCollection) FindWalk(ctx context.Context, fn func(v bson.M) error, where any, ...) error
- func (mc *MongoCollection) IndexesCreateMany(ctx context.Context, models []mongo.IndexModel, ...) (res []string, err error)
- func (mc *MongoCollection) IndexesCreateOne(ctx context.Context, model mongo.IndexModel, ...) (res string, err error)
- func (mc *MongoCollection) IndexesDropAll(ctx context.Context, opts ...*options.DropIndexesOptions) (res bson.Raw, err error)
- func (mc *MongoCollection) IndexesDropOne(ctx context.Context, name string, opts ...*options.DropIndexesOptions) (res bson.Raw, err error)
- func (mc *MongoCollection) IndexesList(ctx context.Context, opts ...*options.ListIndexesOptions) ([]bson.M, error)
- func (mc *MongoCollection) InsertMany(ctx context.Context, items []any, opts ...*options.InsertManyOptions) (newIds []any, err error)
- func (mc *MongoCollection) InsertOne(ctx context.Context, item any, opts ...*options.InsertOneOptions) (newId any, err error)
- func (mc *MongoCollection) Names() (string, string)
- func (mc *MongoCollection) NewOperationLog(do string, set, whr, opt, res any, err error) *MongoOperationLog
- func (mc *MongoCollection) PageWalk(ctx context.Context, fn func(v bson.M) error, page, pageSize int64, ...) (itemTotal, pageTotal int64, err error)
- func (mc *MongoCollection) UpdateByID(ctx context.Context, id, set any, opts ...*options.UpdateOptions) (res *mongo.UpdateResult, err error)
- func (mc *MongoCollection) UpdateMany(ctx context.Context, where, set any, opts ...*options.UpdateOptions) (res *mongo.UpdateResult, err error)
- func (mc *MongoCollection) UpdateOne(ctx context.Context, where, set any, opts ...*options.UpdateOptions) (res *mongo.UpdateResult, err error)
- type MongoOperationLog
- type Mysql
- func (m *Mysql) AddLog(query string, params []any, err error)
- func (m *Mysql) AllColumns(table string) ([]string, error)
- func (m *Mysql) CloseDB()
- func (m *Mysql) ColumnTypes(table string) (map[string]string, error)
- func (m *Mysql) ColumnsWalk(fn func(row *MysqlRow) error, table string) error
- func (m *Mysql) Count(query string, params ...any) (cnt int64, err error)
- func (m *Mysql) DelByIds(table, pk string, ids ...any) (i int64, err error)
- func (m *Mysql) Delete(query string, params ...any) (int64, error)
- func (m *Mysql) GetByIds(table, pk string, ids []any, cols ...string) (rows []*MysqlRow, err error)
- func (m *Mysql) GetDB(useSlave bool) (*sql.DB, error)
- func (m *Mysql) GetOne(table, pk, id string, cols ...string) (*MysqlRow, error)
- func (m *Mysql) IdsWalk(fn func(row *MysqlRow) error, table string, pk string, ids []any, ...) error
- func (m *Mysql) Insert(table string, row *MysqlRow, ignoreOrReplace ...bool) (int64, error)
- func (m *Mysql) InsertBatch(table string, rows []*MysqlRow) (ret int64, err error)
- func (m *Mysql) InsertDuplicate(table string, row *MysqlRow) (int64, error)
- func (m *Mysql) InsertIgnore(table string, row *MysqlRow) (int64, error)
- func (m *Mysql) InsertReplace(table string, row *MysqlRow) (int64, error)
- func (m *Mysql) PopLogs(fn func(ql *MysqlLog) error) error
- func (m *Mysql) SelPage(page, numPerPage int64, table, queryWhere, queryOrder, selCols string, ...) (totalItem, totalPage, curPage int64, err error)
- func (m *Mysql) SelWalk(fn func(row *MysqlRow) error, query string, params ...any) error
- func (m *Mysql) Select(query string, params ...any) (rows []*MysqlRow, err error)
- func (m *Mysql) SetListener(fn func(err error, query string, param ...any))
- func (m *Mysql) Transaction(fn func(tx *sql.Tx, addLog func(query string, params []any, err error)) error, ...) error
- func (m *Mysql) Truncate(table string) error
- func (m *Mysql) Update(query string, params ...any) (int64, error)
- func (m *Mysql) UpdateById(table string, row *MysqlRow, pk, id string) (int64, error)
- type MysqlConnOption
- type MysqlConnParam
- type MysqlLog
- type MysqlRow
- type MysqlTable
- func (mt *MysqlTable) AllWalk(fn func(row *MysqlRow) error, cols ...string) error
- func (mt *MysqlTable) ColumnTypes() (map[string]string, error)
- func (mt *MysqlTable) Count(query string, params ...any) (int64, error)
- func (mt *MysqlTable) DelByIds(ids ...any) (int64, error)
- func (mt *MysqlTable) Delete(query string, params ...any) (int64, error)
- func (mt *MysqlTable) GetByIds(ids []any, cols ...string) ([]*MysqlRow, error)
- func (mt *MysqlTable) GetOne(id string, cols ...string) (*MysqlRow, error)
- func (mt *MysqlTable) IdsWalk(fn func(row *MysqlRow) error, ids []any, cols ...string) error
- func (mt *MysqlTable) Insert(row *MysqlRow) (int64, error)
- func (mt *MysqlTable) InsertBatch(rows []*MysqlRow) (int64, error)
- func (mt *MysqlTable) InsertDuplicate(row *MysqlRow) (int64, error)
- func (mt *MysqlTable) InsertIgnore(row *MysqlRow) (int64, error)
- func (mt *MysqlTable) InsertReplace(row *MysqlRow) (int64, error)
- func (mt *MysqlTable) SelPage(fn func(row *MysqlRow) error, page, numPerPage int64, ...) (int64, int64, int64, error)
- func (mt *MysqlTable) SelWalk(fn func(row *MysqlRow) error, query string, params ...any) error
- func (mt *MysqlTable) Select(query string, params ...any) ([]*MysqlRow, error)
- func (mt *MysqlTable) Transaction(fn func(tx *sql.Tx, addLog func(query string, params []any, err error)) error, ...) error
- func (mt *MysqlTable) Truncate() error
- func (mt *MysqlTable) Update(query string, params ...any) (int64, error)
- func (mt *MysqlTable) UpdateById(row *MysqlRow, id string) (int64, error)
- type Queue
- func (q *Queue) Pause(b bool)
- func (q *Queue) Pop() (any, bool)
- func (q *Queue) PopAll() (ret []any)
- func (q *Queue) PopAllWalk(fn func(item any))
- func (q *Queue) PopWait(td time.Duration) (any, error)
- func (q *Queue) Push(items ...any)
- func (q *Queue) PushWait(items ...any)
- func (q *Queue) TryPushOne(item any) bool
- type RateLimit
- type Redis
- func (r *Redis) Decr(key string, step int) (int64, error)
- func (r *Redis) Del(keys ...any) (int64, error)
- func (r *Redis) Do(cmd string, args ...any) (any, error)
- func (r *Redis) DoContext(ctx context.Context, cmd string, args ...any) (re any, err error)
- func (r *Redis) DoWithTimeout(timeout time.Duration, cmd string, args ...any) (any, error)
- func (r *Redis) Exists(key string) bool
- func (r *Redis) Expire(key string, period time.Duration) (bool, error)
- func (r *Redis) ExpireAt(key string, at int64) (bool, error)
- func (r *Redis) Get(key string) (any, error)
- func (r *Redis) GetBool(key string) (bool, error)
- func (r *Redis) GetInt(key string) (int64, error)
- func (r *Redis) GetNum(key string) (float64, error)
- func (r *Redis) GetOrSingleDo(key string, fn func(key string, redis *Redis) (any, error)) (any, error)
- func (r *Redis) GetStr(key string) (string, error)
- func (r *Redis) HGet(key string, k string) (string, error)
- func (r *Redis) HGetAll(key string) (map[string]string, error)
- func (r *Redis) HGetAllOrSingleDo(key string, fn func(key string, redis *Redis) (any, error)) (map[string]string, error)
- func (r *Redis) HMGet(key string, ks ...any) (map[string]string, error)
- func (r *Redis) HMSet(key string, obj map[string]any) (bool, error)
- func (r *Redis) HSet(key string, k string, v any) (int64, error)
- func (r *Redis) Incr(key string, step int) (int64, error)
- func (r *Redis) RateLimit(key string, rate uint, period time.Duration) (bool, error)
- func (r *Redis) Set(key string, val any, period time.Duration, NXorXX string) (bool, error)
- func (r *Redis) SetLogger(fn func(err error, cmd string, args ...any))
- type RsaKeys
- type WaitGroup
Constants ¶
This section is empty.
Variables ¶
var ErrAesCiphertextTooShort = errors.New(`ciphertext is too short`)
var ErrAesCiphertextWrong = errors.New(`ciphertext is not a multiple of the block size`)
var ErrAmqpChannelClosed = errors.New(`channel is closed`)
var ErrMemCacheKeyExists = errors.New(`key已存在`)
var ErrMemCacheKeyExpired = errors.New(`key已过期`)
var ErrMemCacheKeyNotExist = errors.New(`key不存在`)
var ErrRsaWrongKey = fmt.Errorf("wrong key")
var ErrWrongRedisDsn = errors.New("wrong redis dsn")
Functions ¶
func AddSlashes ¶
AddSlashes 返回在预定义字符之前添加反斜杠的字符串。 预定义字符是:单引号(')、双引号(")、反斜杠(\)
func FileReadLines ¶
FileReadLines 逐行读取文件
func FileReadPart ¶
FileReadPart 读取文件的部分内容
func FileWalkLines ¶
FileWalkLines 逐行分析文件
func HttpSrvRun ¶ added in v0.0.3
HttpSrvRun 使用 http.Server 内置的 Shutdown() 方法优雅地关机
func InterfaceToFloat64 ¶
InterfaceToFloat64 interface 转为 float64
func InterfaceToInt64 ¶
InterfaceToInt64 interface 转为 int64
func NewMongoClient ¶ added in v0.0.18
NewMongoClient Mongo连接客户端
func RsaGenKeys ¶
RsaGenKeys 生成密钥对 bits = 1024/2048
func ShellExecWalk ¶
ShellExecWalk 逐行处理命令执行结果
func StrAToFloat64 ¶
StrAToFloat64 字符串表示的10的-18次方,转为float64
Types ¶
type AmqpClient ¶
type AmqpClient struct { Connection *amqp.Connection // contains filtered or unexported fields }
func (*AmqpClient) GetChannel ¶
func (ac *AmqpClient) GetChannel() (*amqp.Channel, error)
GetChannel 获取一个连接
func (*AmqpClient) PutChannel ¶
func (ac *AmqpClient) PutChannel(ch *amqp.Channel)
PutChannel 归还一个连接
type MemCache ¶
type MemCache struct {
// contains filtered or unexported fields
}
func (*MemCache) GetOrSingleDo ¶ added in v0.0.18
func (s *MemCache) GetOrSingleDo(k string, fn func(k string, mc *MemCache) (any, error)) (any, error)
GetOrSingleDo 合并多个请求为一个,防止击穿
type MongoCollection ¶
type MongoCollection struct { Collection *mongo.Collection Logger func(ctx context.Context, log *MongoOperationLog) }
func NewMongoCollection ¶
func NewMongoCollection(cli *mongo.Client, db, col string, fn func(ctx context.Context, log *MongoOperationLog)) *MongoCollection
NewMongoCollection 新连接
func (*MongoCollection) AggregateWalk ¶
func (mc *MongoCollection) AggregateWalk(ctx context.Context, fn func(v bson.M) error, pipeline mongo.Pipeline, opts ...*options.AggregateOptions) error
AggregateWalk 参考:https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline/#db-collection-aggregate-stages
func (*MongoCollection) BulkWrite ¶
func (mc *MongoCollection) BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (res *mongo.BulkWriteResult, err error)
BulkWrite 批量写入指令
func (*MongoCollection) CountDocuments ¶
func (mc *MongoCollection) CountDocuments(ctx context.Context, where any, opts ...*options.CountOptions) (int64, error)
CountDocuments 统计记录数量
func (*MongoCollection) CursorWalk ¶
func (mc *MongoCollection) CursorWalk(ctx context.Context, fn func(v bson.M) error, cursor *mongo.Cursor) error
CursorWalk 逐条处理结果数据
func (*MongoCollection) DeleteMany ¶
func (mc *MongoCollection) DeleteMany(ctx context.Context, where any, opts ...*options.DeleteOptions) (num int64, err error)
DeleteMany 删除多条数据
func (*MongoCollection) DeleteOne ¶
func (mc *MongoCollection) DeleteOne(ctx context.Context, where any, opts ...*options.DeleteOptions) (num int64, err error)
DeleteOne 删除一条记录
func (*MongoCollection) Distinct ¶
func (mc *MongoCollection) Distinct(ctx context.Context, name string, where any, opts ...*options.DistinctOptions) ([]any, error)
Distinct 查找并去重复
func (*MongoCollection) Drop ¶
func (mc *MongoCollection) Drop(ctx context.Context) (err error)
Drop 清空
func (*MongoCollection) Find ¶
func (mc *MongoCollection) Find(ctx context.Context, where any, opts ...*options.FindOptions) ([]bson.M, error)
Find 按条件查找记录
func (*MongoCollection) FindOne ¶
func (mc *MongoCollection) FindOne(ctx context.Context, where any, opts ...*options.FindOneOptions) (bson.M, error)
FindOne 查找一条记录
func (*MongoCollection) FindOneAndDelete ¶
func (mc *MongoCollection) FindOneAndDelete(ctx context.Context, where any, opts ...*options.FindOneAndDeleteOptions) (res bson.M, err error)
FindOneAndDelete 找到一条记录并删除
func (*MongoCollection) FindOneAndReplace ¶
func (mc *MongoCollection) FindOneAndReplace(ctx context.Context, where, set any, opts ...*options.FindOneAndReplaceOptions) (res bson.M, err error)
FindOneAndReplace 找到一条并替换
func (*MongoCollection) FindOneAndUpdate ¶
func (mc *MongoCollection) FindOneAndUpdate(ctx context.Context, where, set any, opts ...*options.FindOneAndUpdateOptions) (res bson.M, err error)
FindOneAndUpdate 找到一条并更新
func (*MongoCollection) FindWalk ¶
func (mc *MongoCollection) FindWalk(ctx context.Context, fn func(v bson.M) error, where any, opts ...*options.FindOptions) error
FindWalk 按条件查找并逐条处理
func (*MongoCollection) IndexesCreateMany ¶
func (mc *MongoCollection) IndexesCreateMany(ctx context.Context, models []mongo.IndexModel, opts ...*options.CreateIndexesOptions) (res []string, err error)
IndexesCreateMany 创建多条索引
func (*MongoCollection) IndexesCreateOne ¶
func (mc *MongoCollection) IndexesCreateOne(ctx context.Context, model mongo.IndexModel, opts ...*options.CreateIndexesOptions) (res string, err error)
IndexesCreateOne 创建一条索引
func (*MongoCollection) IndexesDropAll ¶
func (mc *MongoCollection) IndexesDropAll(ctx context.Context, opts ...*options.DropIndexesOptions) (res bson.Raw, err error)
IndexesDropAll 删除全部索引
func (*MongoCollection) IndexesDropOne ¶
func (mc *MongoCollection) IndexesDropOne(ctx context.Context, name string, opts ...*options.DropIndexesOptions) (res bson.Raw, err error)
IndexesDropOne 删除一条索引
func (*MongoCollection) IndexesList ¶
func (mc *MongoCollection) IndexesList(ctx context.Context, opts ...*options.ListIndexesOptions) ([]bson.M, error)
IndexesList 获取索引
func (*MongoCollection) InsertMany ¶
func (mc *MongoCollection) InsertMany(ctx context.Context, items []any, opts ...*options.InsertManyOptions) (newIds []any, err error)
InsertMany 插入多条数据
func (*MongoCollection) InsertOne ¶
func (mc *MongoCollection) InsertOne(ctx context.Context, item any, opts ...*options.InsertOneOptions) (newId any, err error)
InsertOne 插入一条数据
func (*MongoCollection) NewOperationLog ¶
func (mc *MongoCollection) NewOperationLog(do string, set, whr, opt, res any, err error) *MongoOperationLog
NewOperationLog 一条日志
func (*MongoCollection) PageWalk ¶
func (mc *MongoCollection) PageWalk( ctx context.Context, fn func(v bson.M) error, page, pageSize int64, where, sort any, opts ...*options.FindOptions, ) (itemTotal, pageTotal int64, err error)
PageWalk 分页取数据
func (*MongoCollection) UpdateByID ¶
func (mc *MongoCollection) UpdateByID(ctx context.Context, id, set any, opts ...*options.UpdateOptions) (res *mongo.UpdateResult, err error)
UpdateByID 按ID更新数据
func (*MongoCollection) UpdateMany ¶
func (mc *MongoCollection) UpdateMany(ctx context.Context, where, set any, opts ...*options.UpdateOptions) (res *mongo.UpdateResult, err error)
UpdateMany 按条件更新多条数据
func (*MongoCollection) UpdateOne ¶
func (mc *MongoCollection) UpdateOne(ctx context.Context, where, set any, opts ...*options.UpdateOptions) (res *mongo.UpdateResult, err error)
UpdateOne 按条件更新一条数据
type MongoOperationLog ¶
type Mysql ¶
type Mysql struct { ConnParam *MysqlConnParam MasterAsSlave bool TimeoutInsert time.Duration TimeoutSelect time.Duration TimeoutUpdate time.Duration TimeoutTrans time.Duration Logger *Queue Listener func(err error, query string, param ...any) // contains filtered or unexported fields }
Mysql 连接实例
func NewMysqlEasy ¶ added in v0.0.12
NewMysqlEasy 快速创建实例
func (*Mysql) AllColumns ¶ added in v0.0.11
AllColumns 表所有的字段
func (*Mysql) ColumnTypes ¶ added in v0.0.11
ColumnTypes 字段对应类型
func (*Mysql) ColumnsWalk ¶ added in v0.0.11
ColumnsWalk 查询数据表结构
func (*Mysql) IdsWalk ¶
func (m *Mysql) IdsWalk(fn func(row *MysqlRow) error, table string, pk string, ids []any, cols ...string) error
IdsWalk 按多个ID取数据并逐条处理
func (*Mysql) InsertBatch ¶
InsertBatch 批量插入
func (*Mysql) InsertDuplicate ¶
InsertDuplicate 插入,如果存在就更新
func (*Mysql) InsertIgnore ¶
InsertIgnore 插入,如果存在就忽略
func (*Mysql) InsertReplace ¶
InsertReplace 插入,如果存在就替换
func (*Mysql) SelPage ¶
func (m *Mysql) SelPage(page, numPerPage int64, table, queryWhere, queryOrder, selCols string, fn func(row *MysqlRow) error, params ...any) (totalItem, totalPage, curPage int64, err error)
SelPage 按页查询
func (*Mysql) SetListener ¶
SetListener 设置监听函数
func (*Mysql) Transaction ¶
func (m *Mysql) Transaction(fn func(tx *sql.Tx, addLog func(query string, params []any, err error)) error, opts *sql.TxOptions) error
Transaction 事务
type MysqlConnOption ¶
type MysqlConnOption struct { Dsn string Addr string DBName string MaxOpenConn int MaxIdleConn int ConnMaxIdleTime time.Duration ConnMaxLifetime time.Duration }
MysqlConnOption 单库连接配置
func NewMysqlConnOption ¶
func NewMysqlConnOption(dsn string, maxOpen, maxIdle int, maxIdleTime, maxLifeTime time.Duration) (*MysqlConnOption, error)
NewMysqlConnOption 得到一个单库连接配置
type MysqlConnParam ¶
type MysqlConnParam struct { Master *MysqlConnOption Slaves []*MysqlConnOption }
MysqlConnParam 连接配置
type MysqlTable ¶
MysqlTable Mysql数据表
func NewMysqlTable ¶
func NewMysqlTable(mysql *Mysql, tableName, primaryKey string) (*MysqlTable, error)
NewMysqlTable 实例化数据表
func (*MysqlTable) AllWalk ¶ added in v0.0.7
func (mt *MysqlTable) AllWalk(fn func(row *MysqlRow) error, cols ...string) error
AllWalk 使用函数遍历全部数据
func (*MysqlTable) ColumnTypes ¶ added in v0.0.11
func (mt *MysqlTable) ColumnTypes() (map[string]string, error)
ColumnTypes 表所有字段及对应类型
func (*MysqlTable) Count ¶
func (mt *MysqlTable) Count(query string, params ...any) (int64, error)
Count 查询数据行数
func (*MysqlTable) DelByIds ¶
func (mt *MysqlTable) DelByIds(ids ...any) (int64, error)
DelByIds 按主键删除一条或多条
func (*MysqlTable) Delete ¶
func (mt *MysqlTable) Delete(query string, params ...any) (int64, error)
Delete 删除数据
func (*MysqlTable) GetByIds ¶
func (mt *MysqlTable) GetByIds(ids []any, cols ...string) ([]*MysqlRow, error)
GetByIds 批量按主键查询
func (*MysqlTable) GetOne ¶
func (mt *MysqlTable) GetOne(id string, cols ...string) (*MysqlRow, error)
GetOne 按主键查询一条
func (*MysqlTable) InsertBatch ¶
func (mt *MysqlTable) InsertBatch(rows []*MysqlRow) (int64, error)
InsertBatch 批量插入
func (*MysqlTable) InsertDuplicate ¶
func (mt *MysqlTable) InsertDuplicate(row *MysqlRow) (int64, error)
InsertDuplicate 唯一索引约束,不存在则新增,存在则更新
func (*MysqlTable) InsertIgnore ¶
func (mt *MysqlTable) InsertIgnore(row *MysqlRow) (int64, error)
InsertIgnore 唯一索引约束,存在则忽略
func (*MysqlTable) InsertReplace ¶
func (mt *MysqlTable) InsertReplace(row *MysqlRow) (int64, error)
InsertReplace 唯一索引约束,不存在则新增,存在则先删再增
func (*MysqlTable) SelPage ¶
func (mt *MysqlTable) SelPage(fn func(row *MysqlRow) error, page, numPerPage int64, queryWhere, queryOrder, selCols string, params ...any) (int64, int64, int64, error)
SelPage 按页查询
func (*MysqlTable) Select ¶
func (mt *MysqlTable) Select(query string, params ...any) ([]*MysqlRow, error)
Select 查询
func (*MysqlTable) Transaction ¶
func (mt *MysqlTable) Transaction(fn func(tx *sql.Tx, addLog func(query string, params []any, err error)) error, opts *sql.TxOptions) error
Transaction 事务操作
func (*MysqlTable) Update ¶
func (mt *MysqlTable) Update(query string, params ...any) (int64, error)
Update 更新数据
func (*MysqlTable) UpdateById ¶
func (mt *MysqlTable) UpdateById(row *MysqlRow, id string) (int64, error)
UpdateById 按主键更新
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
type RateLimit ¶
type RateLimit struct {
// contains filtered or unexported fields
}
func NewRateLimit ¶
NewRateLimit 获得一个实例,每 sec 秒 可以处理 num 次
func (*RateLimit) SetDuration ¶ added in v0.0.6
SetDuration 动态改变间隔参数
type Redis ¶ added in v0.0.14
type Redis struct { Pool *redis.Pool Dsn string Options []redis.DialOption // contains filtered or unexported fields }
func NewRedis ¶ added in v0.0.14
func NewRedis(dsn string, options ...redis.DialOption) (*Redis, error)
NewRedis 得到实例
func (*Redis) DoWithTimeout ¶ added in v0.0.14
DoWithTimeout 带超时的执行
func (*Redis) GetOrSingleDo ¶ added in v0.0.18
func (r *Redis) GetOrSingleDo(key string, fn func(key string, redis *Redis) (any, error)) (any, error)
GetOrSingleDo 防击穿获取数据
func (*Redis) HGetAllOrSingleDo ¶ added in v0.0.18
func (r *Redis) HGetAllOrSingleDo(key string, fn func(key string, redis *Redis) (any, error)) (map[string]string, error)
HGetAllOrSingleDo 防击穿获取数据
type RsaKeys ¶
type RsaKeys struct { PublicKeyStr string PrivateKeyStr string PublicKey *rsa.PublicKey PrivateKey *rsa.PrivateKey }
func NewRsaKeys ¶
NewRsaKeys openssl genrsa -out rsa_private_key.pem 2048 openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
func (*RsaKeys) DecodeWithPrivateKey ¶
DecodeWithPrivateKey 使用私钥解密
func (*RsaKeys) EncodeWithPublicKey ¶
EncodeWithPublicKey 使用公钥加密
func (*RsaKeys) SignWithPrivateKey ¶
SignWithPrivateKey 使用私钥签名
func (*RsaKeys) VerifyWithPublicKey ¶
VerifyWithPublicKey 使用公钥验签