tools

package
v0.0.0-...-c42b9c9 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2023 License: MIT Imports: 25 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildRequestHeaderDic

func BuildRequestHeaderDic(req *http.Request) map[string]string

BuildRequestHeaderDic Description 把http请求头的数据,构造成HttpTrigger的HeaderDic。http请求头key对应的value列表中,只会取出第一个string

func CharacterStringLength

func CharacterStringLength(str string) int

CharacterStringLength 字符串字符长度,即支持中英文混用 i"原字符串"

func CharacterSubString

func CharacterSubString(str string, begin int, end int) string

CharacterSubString 截取字符串,下标为字符计数,即支持中英文混用 str:"原字符串" begin:"起始位置" end:"终止位置+1"

func Commit

func Commit(tx *gorm.DB)

Commit sql

func Crc16Check

func Crc16Check(data []byte) []byte

传入数据内容,返回 crc校验码

func FuncProxy

func FuncProxy(rawFunction interface{}, args ...interface{}) (interface{}, error)

FuncProxy case: 一个返回值; 一个返回值+error; error

func FuncProxyWithoutReturn

func FuncProxyWithoutReturn(rawFunction interface{}, args ...interface{})

FuncProxyWithoutReturn case:无返回值

func GetBusinessNumber

func GetBusinessNumber(bType int) string

GetBusinessNumber func getBusinessNumber

func GetByUrlWithoutParams

func GetByUrlWithoutParams(url string) ([]byte, error)

GetByUrlWithoutParams 从url直接获取返回 @Description: 从url直接获取返回 @param url @return []byte @return error

func GetCacheKey

func GetCacheKey(function interface{}, args ...interface{}) string

GetCacheKey 获取缓存key

func GetDayStrFromTime

func GetDayStrFromTime(timeTime time.Time) string

GetDayStrFromTime with format "2006-01-02 15:04:05"

func GetFmtStr

func GetFmtStr(data interface{}) string

GetFmtStr func

func GetFunctionName

func GetFunctionName(i interface{}, seps ...rune) string

GetFunctionName 例如对于方法"runtime/debug.FreeOSMemory",sep不填,则输出该字符串;sep为'.',则输出"FreeOSMemory"

func GetMd5

func GetMd5(b []byte) string

GetMd5 func getMd5

func GetNoSplitFromTime

func GetNoSplitFromTime(timeTime time.Time) string

GetNoSplitFromTime with format "20060102 15:04:05"

func GetRandNo

func GetRandNo(length int) string

GetRandNo func getRandNo

func GetSplitStrFromTime

func GetSplitStrFromTime(timeTime time.Time) string

GetSplitStrFromTime with format "2006-01-02 15:04:05"

func GetStrFromTime

func GetStrFromTime(timeTime time.Time) string

GetStrFromTime with format "2006-01-02 15:04:05"

func GetTimeFromDayStr

func GetTimeFromDayStr(timeStr string) (time.Time, error)

GetTimeFromDayStr with format "2006-01-02 15:04:05"

func GetTimeFromNoSprit

func GetTimeFromNoSprit(timeStr string) (time.Time, error)

GetTimeFromNoSprit with format "20060102 15:04:05"

func GetTimeFromSpritStr

func GetTimeFromSpritStr(timeStr string) (time.Time, error)

GetTimeFromSpritStr with format "2006-01-02 15:04:05"

func GetTimeFromStr

func GetTimeFromStr(timeStr string) (time.Time, error)

GetTimeFromStr with format "2006-01-02 15:04:05"

func GoRoutine

func GoRoutine(function interface{}, args ...interface{})

GoRoutine 开启协程,已处理好panic。 @function 无返回值 @args function的参数

func HashStrAndConvertToInt

func HashStrAndConvertToInt(str string, lenth int) int

HashStrAndConvertToInt func HashStrAndConvertToInt

func IdCardMask

func IdCardMask(idCard string) string

IdCardMask Description: 只留前3后2,隐藏13位 idCard 身份证号 return: string 隐藏后的身份证号

func IdCardWithoutMonthDay

func IdCardWithoutMonthDay(idCard string) string

IdCardWithoutMonthDay id card cut month and day

func InList

func InList(str string, list []string) bool

InList func

func IsDir

func IsDir(path string) (bool, error)

IsDir judge if dir

func IsFile

func IsFile(path string) (bool, error)

IsFile judge if file

func MailMask

func MailMask(mailAddress string) string

MailMask Description: @前面小于3位全显示+3位*号,大于3位只取前3位+3位*号 mailAddress 邮件地址

func Max

func Max(a, b int) int

Max max(a,b)

func Min

func Min(a, b int) int

Min min(a,b)

func ModStr

func ModStr(s string, len uint32) uint32

ModStr sum32 str, and mod

func PersonalNameMask

func PersonalNameMask(name string) string

PersonalNameMask @Description: 只保留姓氏,复姓两字,name 姓名 return: string 隐藏后的姓名

func RollbackUnlessCommitted

func RollbackUnlessCommitted(tx *gorm.DB)

RollbackUnlessCommitted func

func SendRequest

func SendRequest(client *http.Client, queryStrDic, headerDic map[string]string,
	method, reqUrl string, body interface{}, from, to string,
	disableReqBodyPrint, disableRespPrint bool, queryStr string) ([]byte, error)

SendRequest common func, send request

func SimpleCopyProperties

func SimpleCopyProperties(dst, src interface{}) (err error)

SimpleCopyProperties 浅拷贝src的同名字段到dst dst必须是指针,涉及的字段必须是大写开头,src最好也是指针 如果字段内有引用类型如Slice,Map等,用此方法完成拷贝后,src的引用类型属性内容发生了改变,dst对应的属性中内容也会改变

func TypeIsError

func TypeIsError(inType reflect.Type) bool

TypeIsError 检验是否是error类型

Types

type CacheWrapper

type CacheWrapper struct {
	Cli     *rediscli.RedisCli
	Timeout int
}

CacheWrapper cache wrapper

func (*CacheWrapper) Do

func (p *CacheWrapper) Do(result interface{}, function interface{}, args ...interface{}) error

Do 缓存函数执行的结果,主要用于db相关的单个返回值的查询方法的结果缓存。 @result 缓存的function返回值,必须为指针 @function 返回类型必须为:单个返回值或者单个返回值+error。如果有error且不为nil,则在Do的error里返回 @args function的参数

type HttpOption

type HttpOption func(*HttpTrigger)

HttpOption func

type HttpTrigger

type HttpTrigger struct {
	Method               string
	Url                  string
	From                 string
	To                   string
	DisableReqBodyPrint  bool
	DisableRespBodyPrint bool
	HeaderDic            map[string]string
	QueryDic             map[string]string
	Client               *http.Client
	QueryStr             string //如果不为空,则忽略QueryDic
}

HttpTrigger struct http trigger

func (*HttpTrigger) Execute

func (p *HttpTrigger) Execute(body interface{}) (*response.RetData, error)

Execute send and get response

func (*HttpTrigger) HttpGet

func (p *HttpTrigger) HttpGet(url string, retData interface{}) error

HttpGet JSON Get请求,需要服务端的响应体格式符合RetData resp必须是结构体的指针,字段是响应Data的内容 响应报文JSON的key,需要和respData中的字段名相同(忽略大小写),所以key最好是驼峰命名。否则需要在respData的字段标签中用指定名称,例如`mapstructure:"user_name"`

func (*HttpTrigger) HttpPost

func (p *HttpTrigger) HttpPost(url string, body interface{}, retData interface{}) error

HttpPost JSON Post请求,需要服务端的响应体格式符合RetData body和resp必须是结构体的指针,resp字段是响应Data的内容 响应报文JSON的key,需要和respData中的字段名相同(忽略大小写), 所以key最好是驼峰命名。否则需要在respData的字段标签中用指定名称,例如`mapstructure:"user_name"`

func (*HttpTrigger) SendJsonRequest

func (p *HttpTrigger) SendJsonRequest(client *http.Client, queryStrDic,
	headerDic map[string]string,
	body interface{}) ([]byte, error)

SendJsonRequest func sendJsonRequest

Jump to

Keyboard shortcuts

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