tools

package module
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2022 License: GPL-3.0 Imports: 17 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 CombineFieldFloat32

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

func CombineFieldInt32

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

func DivideInt32

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

func GetCurrPath

func GetCurrPath() string

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

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 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 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