Documentation
¶
Index ¶
- Constants
- Variables
- func BuildGormQuery[T any](query *QueryFull, db *gorm.DB) (*gorm.DB, error)
- func CookieStrReplace(s, k, v string) string
- func FindCookieValue(cookieStr string, key string) (string, bool)
- func GetDiffStruct(oldData interface{}, body interface{}, bodyMap map[string]interface{}) (map[string]interface{}, error)
- func GetEndTimeOfToday() time.Time
- func GetEnv(key, fallback string) string
- func GetFirstDateOfMonth() time.Time
- func GetFirstDateOfWeek() time.Time
- func GetStartTimeOfToday() time.Time
- func IrisErr(ctx iris.Context, input any)
- func IrisErrLog(ctx iris.Context, err error, msg string)
- func IrisErrReturn(ctx iris.Context, input any, statusCode int, businessCode int)
- func IsZeroOfUnderlyingType(x interface{}) bool
- func ListStringToInterface(t []string) []interface{}
- func MBuildFkUnwind(collection, localField, remoteField, remark string) []bson.D
- func MBuildFkUnwindOfEmptyReturn(collection, localField, remoteField, remark string) []bson.D
- func MBuilderFk(collection, localField, remoteField, remark string) bson.D
- func MCreateIndex(ctx context.Context, db *mongo.Collection, indexs ...mongo.IndexModel) error
- func MGen2dSphere(k string) mongo.IndexModel
- func MGenNormal(k string) mongo.IndexModel
- func MGenNormals(keys ...string) mongo.IndexModel
- func MGenUnique(k string, sparse bool) mongo.IndexModel
- func MTN(instance interface{}) string
- func MUserFk(local, remark string) bson.D
- func MUserInfoFk(localField ...string) []bson.D
- func MustFindCookieValue(cookieStr string, key string) string
- func OverrideTemplateWithCookies(templateStr string, templateMap map[string]string, notInTemplateInsert bool) []*http.Cookie
- func ParseCookieStrToCookies(rawStr, sep string) []*http.Cookie
- func ParseCookiesToStr(cookies []*http.Cookie, sep string) string
- func ParseMapToCookies(inputMap map[string]string) []*http.Cookie
- func QueryToMongoPipeline(query *QueryFull) []bson.D
- func RandomInt(start, end int) int
- func RandomStr(n int) string
- func RangeRandomIntSet(start int64, end int64, count int64) []int64
- func RemoveDuplicatesUnordered(elements []string) []string
- func RetryFunc(f func() error, maxRetryCount uint, interval time.Duration) error
- func STN(modelName string) string
- func SaveSliceToFiles[T any](filePath string, values []T, headers ...string) error
- func SplitArrayByFixedSize[T any](arr []T, fixedBulkSize int) [][]T
- func SplitArrayByThreshold[T any](arr []T, threshold int) [][]T
- func StrToB58(s string) string
- func StrToB62(s string) string
- func StrToInt(s string) int64
- func StrToInt64(s string) int64
- func StructCopy(origin, newData interface{}) error
- func StructToMap(s any) (map[string]any, error)
- func ToDiffBson[T any](original, current T, skips []string, keeps []string) (bson.M, error)
- func ToUpdateBson(input any, skips []string, keeps []string) (bson.M, error)
- func TypeChange(input any, wantType string) (any, error)
- type BasePage
- type BaseQuery
- type BaseSort
- type ConcurrentMap
- type FuncCalcTime
- type GenericSlice
- type Geo
- type GeoItem
- type GormQueryResult
- type Kov
- type LocalWork
- func (c *LocalWork[T, R]) GetConcurrency() uint
- func (c *LocalWork[T, R]) Reset()
- func (c *LocalWork[T, R]) Run(runSync bool) error
- func (c *LocalWork[T, R]) SetCall(call func(item T) (R, error)) *LocalWork[T, R]
- func (c *LocalWork[T, R]) SetCallWithClient(call func(item T, client any) (R, error)) *LocalWork[T, R]
- func (c *LocalWork[T, R]) SetChanData(ChanData []T) *LocalWork[T, R]
- func (c *LocalWork[T, R]) SetConcurrency(Concurrency uint) *LocalWork[T, R]
- func (c *LocalWork[T, R]) SetOnSuccess(OnSuccess func(work *LocalWork[T, R], results []R) error) *LocalWork[T, R]
- func (c *LocalWork[T, R]) SetPrintProcess(PrintProcess bool) *LocalWork[T, R]
- func (c *LocalWork[T, R]) SetWeightedClients(clients []WeightedClient) *LocalWork[T, R]
- type ModelCtxMapperPack
- type MongoFacetResult
- type Pk
- type PruneCtxQuery
- func (p *PruneCtxQuery) PruneParse(params map[string]string, searchFields []string, geoKey string) (*QueryFull, error)
- func (p *PruneCtxQuery) PruneParsePage() (*BaseQuery, error)
- func (p *PruneCtxQuery) PruneParseQuery(searchFields []string, geoKey string) (*QueryParse, error)
- func (p *PruneCtxQuery) PruneParseUrlParams() (and []*Kov, or []*Kov, err error)
- func (p *PruneCtxQuery) SetParams(params map[string]string)
- type QueryFull
- type QueryParse
- type RedisWork
- func (c *RedisWork[T]) Db() rueidiscompat.Cmdable
- func (c *RedisWork[T]) GetFirst() string
- func (c *RedisWork[T]) GetItemDelay(start time.Duration, end time.Duration) time.Duration
- func (c *RedisWork[T]) GetLast() string
- func (c *RedisWork[T]) GetNowCount() int64
- func (c *RedisWork[T]) RedisKey() string
- func (c *RedisWork[T]) Run() error
- func (c *RedisWork[T]) RunItemDelay()
- func (c *RedisWork[T]) RunRangeDelay()
- func (c *RedisWork[T]) RunRedisItem(redisKey string) error
- func (c *RedisWork[T]) RunRedisItemParallel(redisKey string) error
- func (c *RedisWork[T]) RunRedisSetRange(redisKey string) error
- func (c *RedisWork[T]) RunSemaphore() error
- func (c *RedisWork[T]) SetCall(call func(id string) ([]T, error))
- func (c *RedisWork[T]) SetDb(db rueidiscompat.Cmdable)
- func (c *RedisWork[T]) SetOnStartup(OnStartup func(self *RedisWork[T]) error)
- func (c *RedisWork[T]) SetOnSuccess(OnSuccess func(self *RedisWork[T]) error)
- func (c *RedisWork[T]) SetRedisKey(redisKey string)
- func (c *RedisWork[T]) StartTime() time.Time
- type RedisWorkStat
- type StructConverter
- func (sc *StructConverter) AddCustomIsZero(value interface{}, fn func(reflect.Value, reflect.StructField) bool)
- func (sc *StructConverter) DiffToBsonM(original, current interface{}, skips []string, keeps []string) (bson.M, error)
- func (sc *StructConverter) InitSpecialTypes()
- func (sc *StructConverter) IsZero(v reflect.Value, field reflect.StructField) bool
- func (sc *StructConverter) StructToBsonM(v interface{}, skips []string, keeps []string) (bson.M, error)
- type ThreadSafeArray
- type TrieMatch
- func (t *TrieMatch) Add(pattern string, method string, raw any) error
- func (t *TrieMatch) Get(pattern string) *TrieNode
- func (t *TrieMatch) Match(pattern string, method string) (*TrieNode, error)
- func (t *TrieMatch) Prefix() string
- func (t *TrieMatch) PruneGet(pattern string) *TrieNode
- func (t *TrieMatch) Remove(pattern string)
- func (t *TrieMatch) RemoveMethod(pattern, method string)
- func (t *TrieMatch) SetPrefix(prefix string)
- func (t *TrieMatch) UpdateRaw(pattern, method string, raw any)
- type TrieNode
- type WeightedClient
Constants ¶
const DefaultUidTag = "uid"
const OpRegex = "regex"
Variables ¶
var AllowOps = []string{"eq", "gt", "gte", "lt", "lte", "ne", "in", "nin", OpRegex}
var MaxRetrySmallError = errors.New("重试次数需要大于1")
var (
NotEnableGlobalSearch = errors.New("未启用全局搜索")
)
Functions ¶
func BuildGormQuery ¶
BuildGormQuery 使用query *QueryFull 构建出对应的查询
func CookieStrReplace ¶
CookieStrReplace 对字符串cookie任何key进行替换改写 返回变更后的cookie字符串
func FindCookieValue ¶
FindCookieValue 从字符串cookie中找到任一Key
func GetDiffStruct ¶
func GetDiffStruct(oldData interface{}, body interface{}, bodyMap map[string]interface{}) (map[string]interface{}, error)
GetDiffStruct 存在与bodyMap中的元素 判断与old和当前body值不同则写入diff bodyMap中的key是 json tag 而不是字段名
func IrisErrLog ¶
func IrisErrReturn ¶
func IsZeroOfUnderlyingType ¶
func IsZeroOfUnderlyingType(x interface{}) bool
func ListStringToInterface ¶
func ListStringToInterface(t []string) []interface{}
func MBuildFkUnwind ¶
MBuildFkUnwind 构建通用解构外键
func MBuildFkUnwindOfEmptyReturn ¶
MBuildFkUnwindOfEmptyReturn preserveNullAndEmptyArrays 默认为false 不存在时则不返回 文档 https://docs.mongodb.com/manual/reference/operator/aggregation/unwind/
func MBuilderFk ¶
MBuilderFk 构建通用外键
func MCreateIndex ¶
func MCreateIndex(ctx context.Context, db *mongo.Collection, indexs ...mongo.IndexModel) error
MCreateIndex 快捷创建索引
func MGenNormals ¶
func MGenNormals(keys ...string) mongo.IndexModel
MGenNormals 复合索引 左匹配原则 请把最常用的字段放前面
func MUserInfoFk ¶
func MustFindCookieValue ¶
MustFindCookieValue 未找到则返回空字符串
func OverrideTemplateWithCookies ¶
func OverrideTemplateWithCookies(templateStr string, templateMap map[string]string, notInTemplateInsert bool) []*http.Cookie
OverrideTemplateWithCookies 多字段覆盖模板cookie中的字段返回 http.Cookie
func ParseCookieStrToCookies ¶
ParseCookieStrToCookies 解析指定分隔符的字符串cookie为 http.Cookie
func ParseCookiesToStr ¶
ParseCookiesToStr 将HTTP Cookie切片编码为Cookie字符串
func ParseMapToCookies ¶
ParseMapToCookies 解析map格式的cookie为 http.Cookie
func QueryToMongoPipeline ¶
func RangeRandomIntSet ¶
RangeRandomIntSet 范围随机正整数但不重复
func RemoveDuplicatesUnordered ¶
RemoveDuplicatesUnordered 删除重复字符串但不保证排序
func SaveSliceToFiles ¶
func SplitArrayByFixedSize ¶
SplitArrayByFixedSize 根据限制分配数组 例如fixedBulkSize为10 则会把arr分为10分
func SplitArrayByThreshold ¶
SplitArrayByThreshold 根据固定值分配成数组 例如threshold为5000 则把arr按照5000一个数组进行切分
func StrToInt64 ¶
func StructCopy ¶
func StructCopy(origin, newData interface{}) error
StructCopy 相同名称的struct field 进行copy
func ToDiffBson ¶
ToDiffBson 两个struct找出不同项 支持skip格式为 a.b.c 只会对比值不同的 两个struct必须相同
func ToUpdateBson ¶
ToUpdateBson struct更新内容给转换为bson.M skip支持格式 a.b.c 代表跳过这个 只会更新存在的 有值的 若原本有值要清除 请使用diff
Types ¶
type ConcurrentMap ¶
type ConcurrentMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewConcurrentMap ¶
func NewConcurrentMap[K comparable, V any]() *ConcurrentMap[K, V]
func (*ConcurrentMap[K, V]) Delete ¶
func (c *ConcurrentMap[K, V]) Delete(key K)
func (*ConcurrentMap[K, V]) Get ¶
func (c *ConcurrentMap[K, V]) Get(key K) (V, bool)
func (*ConcurrentMap[K, V]) GetMap ¶
func (c *ConcurrentMap[K, V]) GetMap() map[K]V
func (*ConcurrentMap[K, V]) Set ¶
func (c *ConcurrentMap[K, V]) Set(key K, value V)
type FuncCalcTime ¶
type FuncCalcTime struct { Name string Stage []timeItem LinePrint bool // contains filtered or unexported fields }
func (*FuncCalcTime) Add ¶
func (c *FuncCalcTime) Add(t string, msg ...interface{})
func (*FuncCalcTime) ChangeLinePrint ¶
func (c *FuncCalcTime) ChangeLinePrint(show bool)
type GenericSlice ¶
type GenericSlice[T any] []T
GenericSlice 是一个泛型类型,用于实现 GORM 的 Serializer 接口 解决sqlite mysql 不支持[]string 这种数组的问题 现在这样是数组解析成了 字符串的 a,b 这样加入db
func (*GenericSlice[T]) Scan ¶
func (gs *GenericSlice[T]) Scan(value interface{}) error
type Geo ¶
type GeoItem ¶
type GeoItem struct { Field string `json:"field,omitempty"` // 获取的字段 ToField string `json:"to_field,omitempty"` // 距离字段名 Lng float64 `json:"lng,omitempty"` // 范围 -180 到 180 Lat float64 `json:"lat,omitempty"` // 范围 -90 到 90 GeoMax int64 `json:"geo_max,omitempty"` // 单位为米 GeoMin int64 `json:"geo_min,omitempty"` // 单位为米 }
type GormQueryResult ¶
func RunGormQuery ¶
RunGormQuery 使用query 解析出gorm的查询结果
type LocalWork ¶
type LocalWork[T any, R any] struct { Name string `json:"name"` // 任务名称 Tid string `json:"tid"` // 任务id 需唯一 NowCount atomic.Int64 // 当前已执行个数 FailCount atomic.Int64 // 失败次数 Running bool // 当前执行状态 Concurrency uint // 线程数量 ForceStop bool // 是否被强制停止 PrintProcess bool // 是否打印进度 默认开启 SuccessStopLimit uint // 成功多少条后停止 ChanData []T // 待处理的数据 Results ThreadSafeArray[R] OnSuccess func(work *LocalWork[T, R], results []R) error // 权重调度相关 WeightedClients []WeightedClient // 带权重的客户端列表 // contains filtered or unexported fields }
LocalWork 本地执行work T是原始数据 R是执行结果
func NewLocalWorkFull ¶
func NewLocalWorkWithClient ¶
func (*LocalWork[T, R]) GetConcurrency ¶
func (*LocalWork[T, R]) SetCallWithClient ¶
func (*LocalWork[T, R]) SetChanData ¶
func (*LocalWork[T, R]) SetConcurrency ¶
func (*LocalWork[T, R]) SetOnSuccess ¶
func (*LocalWork[T, R]) SetPrintProcess ¶
func (*LocalWork[T, R]) SetWeightedClients ¶
func (c *LocalWork[T, R]) SetWeightedClients(clients []WeightedClient) *LocalWork[T, R]
type ModelCtxMapperPack ¶
type ModelCtxMapperPack struct { InjectData map[string]any `json:"inject_data,omitempty"` // 注入数据 默认覆盖 DropKeys []string `json:"drop_keys,omitempty"` // 需要丢弃的key }
ModelCtxMapperPack 解析body数据包 所有map key 支持 a.b.c 但是对应的是json tag标签名
func (*ModelCtxMapperPack) Process ¶
func (m *ModelCtxMapperPack) Process(data any) error
type MongoFacetResult ¶
type PruneCtxQuery ¶
type PruneCtxQuery struct {
// contains filtered or unexported fields
}
func NewPruneCtxQuery ¶
func NewPruneCtxQuery() *PruneCtxQuery
func (*PruneCtxQuery) PruneParse ¶
func (*PruneCtxQuery) PruneParsePage ¶
func (p *PruneCtxQuery) PruneParsePage() (*BaseQuery, error)
PruneParsePage 解析出 page page_size sort
func (*PruneCtxQuery) PruneParseQuery ¶
func (p *PruneCtxQuery) PruneParseQuery(searchFields []string, geoKey string) (*QueryParse, error)
PruneParseQuery 解析出 _last geo search
func (*PruneCtxQuery) PruneParseUrlParams ¶
func (p *PruneCtxQuery) PruneParseUrlParams() (and []*Kov, or []*Kov, err error)
PruneParseUrlParams 纯解析url上的参数
func (*PruneCtxQuery) SetParams ¶
func (p *PruneCtxQuery) SetParams(params map[string]string)
type QueryFull ¶
type QueryFull struct { *QueryParse *BaseQuery Pks []*Pk `json:"pks,omitempty"` GetCount bool `json:"get_count,omitempty"` // 获取过滤总数 }
type QueryParse ¶
type QueryParse struct { And []*Kov `json:"and,omitempty"` Or []*Kov `json:"or,omitempty"` Geos *GeoItem `json:"geos,omitempty"` }
func (*QueryParse) InsertOrReplaces ¶
func (c *QueryParse) InsertOrReplaces(target string, data ...*Kov)
type RedisWork ¶
type RedisWork[T any] struct { PlatformName string // 平台名 PlatformEng string // 平台英文名 Name string // 任务名称 Description string // 更多描述 BulkIds []string // id列表 BulkStart int64 // id起始值 BulkEnd int64 // id截止值 DefaultStartCount int64 // 默认启动数 DefaultEndCount int64 // 默认截止数值 NowCount atomic.Int64 // 当前已执行个数 FileName string // 保存文件名 Concurrency uint // 线程数量 Results []T // 结果保存 Running bool // 当前执行状态 FetchCall func(id string) ([]T, error) // 获取单个 FetchError func(id string, err error) ([]T, error) // 获取错误 ForceStop bool // 是否被强制停止 RangeReverse bool // 范围旋转 默认从小到大 如果设置为true 则是从大到小 InjectData map[string]any // OnSuccess func(self *RedisWork[T]) error // 当成功时执行 OnStartup func(self *RedisWork[T]) error // 启动时 OnRangeStart func(scopes []string, self *RedisWork[T]) []string OnRangSuccess func(self *RedisWork[T], results []T, resultMap map[string][]T) error OnSingleSuccess func(self *RedisWork[T], results []T, target string) error ItemDelayStart time.Duration // 每获取一个的间隔时间起始点 ItemDelayEnd time.Duration // 每获取一个的间隔时间终止点 RangeDelayStart time.Duration RangeDelayEnd time.Duration Stat RedisWorkStat // contains filtered or unexported fields }
func NewRedisWork ¶
func NewRedisWork[T any](name string, redisClient rueidiscompat.Cmdable) *RedisWork[T]
func (*RedisWork[T]) Db ¶
func (c *RedisWork[T]) Db() rueidiscompat.Cmdable
func (*RedisWork[T]) GetItemDelay ¶
func (*RedisWork[T]) GetNowCount ¶
func (*RedisWork[T]) RunItemDelay ¶
func (c *RedisWork[T]) RunItemDelay()
func (*RedisWork[T]) RunRangeDelay ¶
func (c *RedisWork[T]) RunRangeDelay()
func (*RedisWork[T]) RunRedisItem ¶
RunRedisItem 按批次处理单个 会等待批次结束 性能稍弱
func (*RedisWork[T]) RunRedisItemParallel ¶
RunRedisItemParallel 多线程并行版 性能高
func (*RedisWork[T]) RunRedisSetRange ¶
RunRedisSetRange 按范围批次处理 会等待批次结束 性能若
func (*RedisWork[T]) RunSemaphore ¶
func (*RedisWork[T]) SetDb ¶
func (c *RedisWork[T]) SetDb(db rueidiscompat.Cmdable)
func (*RedisWork[T]) SetOnStartup ¶
func (*RedisWork[T]) SetOnSuccess ¶
func (*RedisWork[T]) SetRedisKey ¶
type RedisWorkStat ¶
type StructConverter ¶
type StructConverter struct { CustomIsZero map[reflect.Type]func(reflect.Value, reflect.StructField) bool SpecialTypes []reflect.Type // 特殊结构体类型列表 }
StructConverter 作用在于struct中如果需要更新的时候 不要使用bson.M来手动设置字段名 这样又没有编辑器提示 字段变更时也很难同步 可以采取这种方式 特点是会自动去除0值的字段最后只保留有值的产出bson.M 那在某些情况下 会从db中取出存储的哪一行 然后跟当前的进行对比 这时候就使用 diff 的模式 对比两个struct中的不同项进行变更 还有某些情况下 需要从body中取出更新项 需要使用 pipe里的diff算法
func NewStructConverter ¶
func NewStructConverter() *StructConverter
func (*StructConverter) AddCustomIsZero ¶
func (sc *StructConverter) AddCustomIsZero(value interface{}, fn func(reflect.Value, reflect.StructField) bool)
func (*StructConverter) DiffToBsonM ¶
func (sc *StructConverter) DiffToBsonM(original, current interface{}, skips []string, keeps []string) (bson.M, error)
DiffToBsonM 缺点在于如果有内联的struct 如果原始数据中没有定义上层 则无法正确update 比如{city:{name:"新名称"}} 如果原始数据中没有 city字段则无法通过{city.name:"新名称"}进行更新?
func (*StructConverter) InitSpecialTypes ¶
func (sc *StructConverter) InitSpecialTypes()
func (*StructConverter) IsZero ¶
func (sc *StructConverter) IsZero(v reflect.Value, field reflect.StructField) bool
func (*StructConverter) StructToBsonM ¶
type ThreadSafeArray ¶
type ThreadSafeArray[T any] struct { // contains filtered or unexported fields }
ThreadSafeArray 线程安全的数组
func (*ThreadSafeArray[T]) Append ¶
func (t *ThreadSafeArray[T]) Append(value ...T)
func (*ThreadSafeArray[T]) Count ¶
func (t *ThreadSafeArray[T]) Count() int
func (*ThreadSafeArray[T]) Get ¶
func (t *ThreadSafeArray[T]) Get(index int) T
func (*ThreadSafeArray[T]) GetAll ¶
func (t *ThreadSafeArray[T]) GetAll() []T
func (*ThreadSafeArray[T]) Pop ¶
func (t *ThreadSafeArray[T]) Pop(count int) []T
type TrieMatch ¶
type TrieMatch struct {
// contains filtered or unexported fields
}
func NewTrieMatch ¶
func NewTrieMatch() *TrieMatch
func (*TrieMatch) RemoveMethod ¶
RemoveMethod 删除匹配项对应的方法 eg: /a/b/c [GET,POST] --> /a/b/c [GET] 但是如果路径下仅此一个方法 则会执行删除路径 eg: /a/b/c [GET] - GET --> /a/b
type TrieNode ¶
type TrieNode struct {
// contains filtered or unexported fields
}
func (*TrieNode) GetMatchParams ¶
GetMatchParams 获取匹配的参数 :board 但不会校验格式
func (*TrieNode) IsValidMethod ¶
type WeightedClient ¶
type WeightedClient struct { Client any `json:"client"` // The client instance (can be any type) Weight uint `json:"weight"` // The weight of this client (higher means more work assigned) }
WeightedClient represents a client with an associated weight
Source Files
¶
- array_split.go
- cookie.go
- ctx_mapper.go
- dateTime.go
- env.go
- files.go
- funcTime.go
- gorm.go
- handler_iris.go
- handler_query.go
- handler_query_gorm.go
- handler_query_mongo.go
- hexConv.go
- local_work.go
- mongo.go
- mongo_fk.go
- mongo_geo.go
- mongo_update.go
- redis_work.go
- retry.go
- struct_2_map.go
- syncMap.go
- thread_safe_array.go
- tools.go
- trie.go
- types.go