tools

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: GPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ArrayChunkInt32

func ArrayChunkInt32(array []int32, num int) [][]int32

ArrayChunkInt32 数组分组

func ArrayChunkStr

func ArrayChunkStr(array []string, num int) [][]string

ArrayChunkStr 数组分组

func CallFunc

func CallFunc(body CallBody) (result []interface{}, err error)

CallFunc 利用反射动态执行函数

func CheckEsMapExist added in v0.0.18

func CheckEsMapExist(ctx context.Context, client *elastic.Client, index string) bool

func CombineFieldFloat32

func CombineFieldFloat32(old interface{}, ne interface{}) (float32, error)

func CombineFieldInt32

func CombineFieldInt32(old interface{}, ne interface{}) (int32, error)

func CopyEsIndex added in v0.0.18

func CopyEsIndex(ctx context.Context, client *elastic.Client, src string, target string) (success bool, err error)

CopyEsIndex 复制 es 索引

func DivideInt32

func DivideInt32(dividend int32, divisor int32, mul ...int32) (float64, error)

func GetCurrPath

func GetCurrPath() string

GetCurrPath 获取当前可执行文件所在的磁盘路径

func GetCurrentSliceESIndex added in v0.0.18

func GetCurrentSliceESIndex(indexName string, timer ...time.Time) (index string)

GetCurrentSliceESIndex 分片基础函数

func GetESMapping added in v0.0.18

func GetESMapping(ctx context.Context, client *elastic.Client, index ...string) (result map[string]interface{}, err error)

GetESMapping 获取指定索引的 mapping

func GetEarliestDate added in v0.0.18

func GetEarliestDate() time.Time

GetEarliestDate 分片查询时间临界点

func GetEsIndex added in v0.0.18

func GetEsIndex(indexName string, params map[string]interface{}) []string

GetEsIndex 默认获取批量索引的方法

func GetSliceESIndexByDateRange added in v0.0.18

func GetSliceESIndexByDateRange(indexName string, startDate string, endDate string) (indexArr []string, err error)

GetSliceESIndexByDateRange 根据时间格式过滤索引 可传递的格式有 2006-01-02 2006-1-02 2006-1-2 20060102

func GetSliceESIndexByTimeRange added in v0.0.18

func GetSliceESIndexByTimeRange(indexName string, startTime time.Time, endTime time.Time) (indexArr []string, err error)

GetSliceESIndexByTimeRange 根据时间格式过滤索引

func GetStructStringField

func GetStructStringField(input interface{}, key string) (value string, err error)

GetStructStringField 获取struct中指定key的string值

func HTTPGet

func HTTPGet(requestURI string, params map[string]string, header map[string]string) ([]byte, error)

HTTPGet 简化请求

func HTTPPost

func HTTPPost(requestURI string, params map[string]string, header map[string]string) ([]byte, error)

func InterfaceToResult

func InterfaceToResult(resultList []interface{}, returnItems ...interface{}) error

InterfaceToResult 将interface 里面的字段赋值给后面各种变量

func PrintJson added in v0.0.13

func PrintJson(tag string, data interface{}, format ...bool)

PrintJson 将数据打印成 json格式

func SetLogger added in v0.0.16

func SetLogger(logger Logger)

func Split

func Split(str string, step string) []string

func StructByReflect

func StructByReflect(beforeMap map[string]interface{}, inStructPtr interface{}) error

StructByReflect 遍历struct并且自动进行赋值

func TimeFormatInt32

func TimeFormatInt32(tt int32, format ...string) (string, error)

Types

type CallBody

type CallBody struct {
	FuncName interface{}   // 要执行的函数本体
	Params   []interface{} // 要传的函数参数, 需要类型和数量都保持一致
}

CallBody 单个函数的请求体

type CallTask

type CallTask struct {
	MaxTime  time.Duration
	TaskList []CallBody
	Ctx      context.Context
}

CallTask 发起并发执行任务

type KT

type KT struct {
	Key  string
	Type string
}

func GetStructKeyType

func GetStructKeyType(structName interface{}) ([]KT, error)

GetStructKeyType 获取struct的kv结构

type Logger added in v0.0.16

type Logger func(level int, traceData map[string]string, msg string, v ...interface{})

type ResponseBody

type ResponseBody struct {
	Result []interface{} // 函数返回的所有结果(包括常用 error), 包括业务返回的错误
	Index  int           // 传入时的顺序
	Err    error         // 函数在 callBack 里调用时的错误
}

func BatchExec

func BatchExec(task CallTask) (resultList []ResponseBody, err error)

BatchExec 并发执行, 需限制总的并发数量

func SyncBatchExec

func SyncBatchExec(task CallTask) (resultList []ResponseBody, err error)

SyncBatchExec 同步执行, 用于不方便并发执行的业务

func (*ResponseBody) GetResult

func (resp *ResponseBody) GetResult(returnItems ...interface{}) error

GetResult 将返回结果以反射的方式赋值给传入参数

Directories

Path Synopsis
elasticsearch

Jump to

Keyboard shortcuts

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