utility

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2022 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	RegexY, _      = regexp.Compile(`^\d{4}$`)
	RegexYM, _     = regexp.Compile(`^\d{4}-\d{2}$`)
	RegexYMD, _    = regexp.Compile(`^\d{4}-\d{2}-\d{2}$`)
	RegexYMDHI, _  = regexp.Compile(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$`)
	RegexYMDHIS, _ = regexp.Compile(`^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$`)
)
View Source
var (
	NumberLetters = []string{"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
)

Functions

func Base64Encode

func Base64Encode(str string) string

func CamelToCase

func CamelToCase(name string) string

func ConvertStr

func ConvertStr(value interface{}) string

func CosDeleteFile

func CosDeleteFile(conf config.CosConfig, key string) error

CosDeleteFile 删除单个文件

func CosGetCredential

func CosGetCredential(conf config.CosConfig, folder string, action []string) (*sts.CredentialResult, error)

CosGetCredential 获取COS临时密钥

func CosGetUploadCredential

func CosGetUploadCredential(conf config.CosConfig, folder string) (*sts.CredentialResult, error)

CosGetUploadCredential 获取COS上传临时密钥

func CosNewClient

func CosNewClient(conf config.CosConfig, action []string) (*cos.Client, error)

CosNewClient 实例化客户端

func CosUploadFile

func CosUploadFile(conf config.CosConfig, key string, file string) error

CosUploadFile 上传本地文件

func CosUploadRemoteFile

func CosUploadRemoteFile(conf config.CosConfig, key string, remoteUrl string) error

CosUploadRemoteFile 上传远程文件

func CosUploadStreamFile

func CosUploadStreamFile(conf config.CosConfig, key string, stream io.Reader) error

CosUploadStreamFile 上传流文件

func CurrentDateTime

func CurrentDateTime() (microDate int64, microTime int64)

CurrentDateTime 获取当前日和时的毫秒

func DiscountText

func DiscountText(val float32, dft ...string) string

DiscountText 把小数折扣转成文字

func FenToYuan

func FenToYuan(val int, thousandth ...bool) string

FenToYuan 分转元(最多两位小数)

func Float32ToString

func Float32ToString(val float32) string

func Float64ToString

func Float64ToString(val float64) string

func FormatMicroDateTimeShortString

func FormatMicroDateTimeShortString(value int64, format string, sep string) (text string)

FormatMicroDateTimeShortString 把时间格式化成 今天 18:12, 明天 09:22,昨天、前天

func FormatMicroTime

func FormatMicroTime(value int64, format ...string) string

* 年:2006 月:01 日:02 时:15 分:04 秒:05 毫秒:.000

func FormatMicroTimeShortString

func FormatMicroTimeShortString(value int64) (text string)

func FormatSecondTime

func FormatSecondTime(value int64, format ...string) string

func GetFirstDateOfWeek

func GetFirstDateOfWeek() (weekMonday string)

获取本周一时间戳

func GetPost

func GetPost(c *gin.Context, key string) *queryFormData

func GetPostArray

func GetPostArray(c *gin.Context, key string) *queryFormDataArray

func GetQuery

func GetQuery(c *gin.Context, key string) *queryFormData

func GetQueryArray

func GetQueryArray(c *gin.Context, key string) *queryFormDataArray

func GetTodayStartMircoTime

func GetTodayStartMircoTime() int64

GetTodayStartMircoTime 获取当日零点时间戳(毫秒)

func GetTodayStartSecondTime

func GetTodayStartSecondTime() int64

GetTodayStartSecondTime 获取当日零点时间戳(秒)

func Hex16ToFloat64

func Hex16ToFloat64(bys []byte) float64

func Hex16ToInt

func Hex16ToInt(bys []byte) int

func Hex16ToInt64

func Hex16ToInt64(bys []byte) int64

func Hex16ToUint64

func Hex16ToUint64(bys []byte) uint64

func HexIEEE754ToFloat

func HexIEEE754ToFloat(bys []byte) float64

func HttpBuildQuery

func HttpBuildQuery(data map[string]interface{}) string

func HttpGet

func HttpGet(accessUrl string, option *HttpClientOptions) (response []byte, ex *exception.Error)

func HttpPostFile

func HttpPostFile(url string, filename string) ([]byte, *exception.Error)

func HttpPostForm

func HttpPostForm(accessUrl string, option *HttpClientOptions) (response []byte, ex *exception.Error)

func HttpPostString

func HttpPostString(accessUrl string, option *HttpClientOptions) (response []byte, ex *exception.Error)

func HttpPostString1

func HttpPostString1(url string, data string) ([]byte, *exception.Error)

func InArrayByFloat64

func InArrayByFloat64(val float64, arr []float64) bool

func InArrayByInt

func InArrayByInt(val int, arr []int) bool

func InArrayByInt64

func InArrayByInt64(val int64, arr []int64) bool

func InArrayByStr

func InArrayByStr(val string, arr []string) bool

func InetAtoN

func InetAtoN(ip string) int64

func InetNtoA

func InetNtoA(ip int64) string

func Int64ArrayDiff

func Int64ArrayDiff(array1 []int64, othersParams ...[]int64) []int64

Int64ArrayDiff 数组差异项的集合(第一个有,其它没有的)

func Int64ArrayIntersect

func Int64ArrayIntersect(array1 []int64, othersParams ...[]int64) []int64

Int64ArrayIntersect 数组交集项的集合(所有数据都有项)

func Int64ToFloat32

func Int64ToFloat32(val int64) float32

func Int64ToFloat64

func Int64ToFloat64(val int64) float64

func Int64ToString

func Int64ToString(val int64) string

func IntAConvStrA

func IntAConvStrA(data []int) (result []string)

func IntArrayDiff

func IntArrayDiff(array1 []int, othersParams ...[]int) []int

IntArrayDiff 数组差异项的集合(第一个有,其它没有的)

func IntArrayIntersect

func IntArrayIntersect(array1 []int, othersParams ...[]int) []int

IntArrayIntersect 数组交集项的集合(所有数据都有项)

func IntToFloat32

func IntToFloat32(val int) float32

func IntToFloat64

func IntToFloat64(val int) float64

func IntToHex16

func IntToHex16(num interface{}) []byte

func IntToHex36

func IntToHex36(num int) string

func IntToString

func IntToString(val int) string

func Is32BitCode

func Is32BitCode(val string) (match bool)

Is32BitCode 检查是否为32位Code字符

func IsEmpty

func IsEmpty(val interface{}) bool

IsEmpty 检查是否空值

func IsLetter

func IsLetter(val string) (match bool)

IsLetter 检查是否为纯字母(大小写)

func IsLetterAndNumber

func IsLetterAndNumber(val string) (match bool)

IsLetterAndNumber 检查是否为字母+数字

func IsNumber

func IsNumber(val string) (match bool)

IsNumber 检查是否为纯数字

func IsNumeric

func IsNumeric(val string) (match bool)

IsNumeric 检查是否为数字(包含小数、正负数据)

func IsTextKey

func IsTextKey(val string) (match bool)

IsTextKey 检查是否为安全字符

func JsonToMap

func JsonToMap(str string) (map[string]interface{}, error)

func JsonToString

func JsonToString(val interface{}) string

func KSort

func KSort(data map[string]interface{}) map[string]interface{}

func MD5

func MD5(str string) string

func MD5RAW

func MD5RAW(str string) string

func MD5Sign

func MD5Sign(dict map[string]interface{}, secret string) (sign string)

func MD5withKEY

func MD5withKEY(str string, key string) string

func MicroTime

func MicroTime() int64

MicroTime 单位:毫秒

func MicroTimeDate

func MicroTimeDate() int64

func MicroTimeHour

func MicroTimeHour() int64

func MicroTimeMinute

func MicroTimeMinute() int64

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte) []byte

PKCS7UnPadding return unPadding []Byte plantText

func Paginate

func Paginate(c *gin.Context, defaultSize ...int) (int, int)

func PrintJSON

func PrintJSON(val interface{})

func RandomInt64

func RandomInt64(nums int) int64

func RandomString

func RandomString(nums int) string

func RemoteIp

func RemoteIp(c *gin.Context) string

func RemoveDuplicatesAndEmpty

func RemoveDuplicatesAndEmpty(data []string) (ret []string)

RemoveDuplicatesAndEmpty 过滤重复值和空值

func SHA1

func SHA1(str string) string

func SHA1HMAC

func SHA1HMAC(key string, str string) string

func SHA256

func SHA256(str string) string

func SecondTime

func SecondTime() int64

SecondTime 单位:秒

func StrAConvIntA

func StrAConvIntA(data []string) (result []int)

func StringArrayDiff

func StringArrayDiff(array1 []string, othersParams ...[]string) []string

StringArrayDiff 数组差异项的集合(第一个有,其它没有的)

func StringArrayIntersect

func StringArrayIntersect(array1 []string, othersParams ...[]string) []string

StringArrayIntersect 数组交集项的集合(所有数据都有项)

func StringToFloat64

func StringToFloat64(val string) float64

func StringToInt

func StringToInt(val string) int

func StringToInt64

func StringToInt64(val string) int64

func StringToJson

func StringToJson(val string, target interface{})

func StringToTime

func StringToTime(str string) int64

字符串日期转时间戳

func StringToXml

func StringToXml(val string, target interface{})

func Thousandth

func Thousandth(val interface{}) string

func ThousandthDecimals

func ThousandthDecimals(val interface{}, decimals int) string

func WxCodeToSession

func WxCodeToSession(code string, conf config.WeiXinMcpConfig) ([]byte, *exception.Error)

WxCodeToSession 换取授权密钥

func WxCreateMpMenu

func WxCreateMpMenu(menu string, accessToken string) *exception.Error

WxCreateMpMenu 创建微信公众号菜单

func WxCreateQrcodeUnlimited

func WxCreateQrcodeUnlimited(sceneId string, page string, width int, accessToken string) ([]byte, *exception.Error)

WxCreateQrcodeUnlimited 创建微信公众号、小程序二维码(永久有效,数量暂无限制)

func WxGetAccessToken

func WxGetAccessToken(redis *redis.Client, conf config.WeiXinMcpConfig, force bool) (string, *exception.Error)

WxGetAccessToken 获取Token

func WxSendMpContent

func WxSendMpContent(openId string, accessToken string, msgtype string, data string) *exception.Error

WxSendMpContent 发送客服消息

func WxShowQrCode

func WxShowQrCode(ticket string) string

WxShowQrCode 通过ticket换取二维码

func XmlToString

func XmlToString(val interface{}) string

Types

type HttpClientOptions

type HttpClientOptions struct {
	CookieUrl     *url.URL
	Cookies       []*http.Cookie
	Headers       map[string]string
	FormData      map[string]string
	Proxy         string
	SslSkipVerify bool
	Timeout       time.Duration
}

type Int64Array

type Int64Array []int64

func (Int64Array) InArray

func (arr Int64Array) InArray(val int64) bool

type Int64Int64Map

type Int64Int64Map map[int64]int64

func (Int64Int64Map) GetKVS

func (m Int64Int64Map) GetKVS() (keys []int64, values []int64)

func (Int64Int64Map) GetKeys

func (m Int64Int64Map) GetKeys() []int64

func (Int64Int64Map) GetValues

func (m Int64Int64Map) GetValues() []int64

type Int64IntMap

type Int64IntMap map[int64]int

func (Int64IntMap) GetKeys

func (m Int64IntMap) GetKeys() []int64

func (Int64IntMap) GetValues

func (m Int64IntMap) GetValues() []int

type Int64StringMap

type Int64StringMap map[int64]string

func (Int64StringMap) GetKVS

func (m Int64StringMap) GetKVS() (keys []int64, values []string)

func (Int64StringMap) GetKeys

func (m Int64StringMap) GetKeys() []int64

func (Int64StringMap) GetValues

func (m Int64StringMap) GetValues() []string

type IntArray

type IntArray []int

func (IntArray) InArray

func (arr IntArray) InArray(val int) bool

type IntBoolMap

type IntBoolMap map[int]bool

func (IntBoolMap) GetKeys

func (m IntBoolMap) GetKeys() []int

type IntInt64Map

type IntInt64Map map[int]int64

func (IntInt64Map) GetKVS

func (m IntInt64Map) GetKVS() (keys []int, values []int64)

func (IntInt64Map) GetKeys

func (m IntInt64Map) GetKeys() []int

func (IntInt64Map) GetValues

func (m IntInt64Map) GetValues() []int64

type IntIntMap

type IntIntMap map[int]int

func (IntIntMap) GetKVS

func (m IntIntMap) GetKVS() (keys []int, values []int)

func (IntIntMap) GetKeys

func (m IntIntMap) GetKeys() []int

func (IntIntMap) GetValues

func (m IntIntMap) GetValues() []int

type IntStringMap

type IntStringMap map[int]string

func (IntStringMap) GetKVS

func (m IntStringMap) GetKVS() (keys []int, values []string)

func (IntStringMap) GetKeys

func (m IntStringMap) GetKeys() []int

func (IntStringMap) GetValues

func (m IntStringMap) GetValues() []string

type StrArray

type StrArray []string

func (StrArray) InArray

func (arr StrArray) InArray(val string) bool

type StringBoolMap

type StringBoolMap map[string]bool

func (StringBoolMap) GetKeys

func (m StringBoolMap) GetKeys() []string

type StringIntMap

type StringIntMap map[string]int

func (StringIntMap) GetKVS

func (m StringIntMap) GetKVS() (keys []string, values []int)

func (StringIntMap) GetKeys

func (m StringIntMap) GetKeys() []string

func (StringIntMap) GetValues

func (m StringIntMap) GetValues() []int

type StringStringMap

type StringStringMap map[string]string

func (StringStringMap) GetKVS

func (m StringStringMap) GetKVS() (keys []string, values []string)

func (StringStringMap) GetKeys

func (m StringStringMap) GetKeys() []string

func (StringStringMap) GetPairs

func (m StringStringMap) GetPairs() (pairs []string)

func (StringStringMap) GetValues

func (m StringStringMap) GetValues() []string

type TimeInt64Data

type TimeInt64Data struct {
	Value int64
}

func GetTimeInt64

func GetTimeInt64(val int64) *TimeInt64Data

func (*TimeInt64Data) NextDay

func (d *TimeInt64Data) NextDay() int64

func (*TimeInt64Data) NextMonth

func (d *TimeInt64Data) NextMonth() int64

func (*TimeInt64Data) NextYear

func (d *TimeInt64Data) NextYear() int64

func (*TimeInt64Data) PrevDay

func (d *TimeInt64Data) PrevDay() int64

func (*TimeInt64Data) PrevMonth

func (d *TimeInt64Data) PrevMonth() int64

func (*TimeInt64Data) PrevYear

func (d *TimeInt64Data) PrevYear() int64

type TimeStringData

type TimeStringData struct {
	Value string
}

func GetTimeString

func GetTimeString(val string) *TimeStringData

func (*TimeStringData) CurrentMonthFirstDayMicroTime

func (d *TimeStringData) CurrentMonthFirstDayMicroTime() int64

func (*TimeStringData) CurrentYearFirstMonthMicroTime

func (d *TimeStringData) CurrentYearFirstMonthMicroTime() int64

func (*TimeStringData) DateTime

func (d *TimeStringData) DateTime() *time.Time

func (*TimeStringData) MicroTime

func (d *TimeStringData) MicroTime() int64

func (*TimeStringData) SecondTime

func (d *TimeStringData) SecondTime() int64

type WxAccessTokenData

type WxAccessTokenData struct {
	AccessToken string        `json:"access_token"`
	ExpiresIn   time.Duration `json:"expires_in"`
	WxResponseErrorData
}

type WxBizDataCrypt

type WxBizDataCrypt struct {
	AppId      string
	SessionKey string
}

WxBizDataCrypt represents an active WxBizDataCrypt object

func (*WxBizDataCrypt) Decrypt

func (wxCrypt *WxBizDataCrypt) Decrypt(encryptedData string, iv string, isJSON bool) (interface{}, *WxResponseErrorData)

Decrypt Weixin APP's AES Data If isJSON is true, Decrypt return JSON type. If isJSON is false, Decrypt return map type.

type WxMediaData

type WxMediaData struct {
	MediaId string `json:"media_id"`
	Url     string `json:"url"`
	WxResponseErrorData
}

func WxAddMaterial

func WxAddMaterial(file string, accessToken string, fileType string) (*WxMediaData, *exception.Error)

WxAddMaterial 上传微信永久素材 type限制: 图片(image)、语音(voice)、视频(video)和缩略图(thumb)

type WxQrcodeData

type WxQrcodeData struct {
	Ticket        string `json:"ticket"`
	ExpireSeconds int    `json:"expire_seconds"`
	Url           string `json:"url"`
	WxResponseErrorData
}

func WxCreateQrcode

func WxCreateQrcode(sceneId string, accessToken string) (*WxQrcodeData, *exception.Error)

WxCreateQrcode 创建微信公众号二维码

type WxQrcodeUnlimitedData

type WxQrcodeUnlimitedData struct {
	ContentType string `json:"contentType"`
	Buffer      string `json:"buffer"`
	WxResponseErrorData
}

type WxResponseErrorData

type WxResponseErrorData struct {
	ErrCode int    `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

type WxUploadData

type WxUploadData struct {
	Type      string `json:"type"`
	MediaId   string `json:"media_id"`
	CreatedAt int    `json:"created_at"`
	WxResponseErrorData
}

func WxUploadFile

func WxUploadFile(file string, accessToken string, fileType string) (*WxUploadData, *exception.Error)

WxUploadFile 上传微信临时素材

type WxUserInfoData

type WxUserInfoData struct {
	Openid        string `json:"openid"`
	UnionId       string `json:"unionid"`
	Nickname      string `json:"nickname"`
	Sex           int64  `json:"sex"`
	HeadImgUrl    string `json:"headimgurl"`
	Subscribe     int64  `json:"subscribe"`
	SubscribeTime int64  `json:"subscribe_time"`
	WxResponseErrorData
}

func WxGetUserInfo

func WxGetUserInfo(openId string, accessToken string) (*WxUserInfoData, *exception.Error)

WxGetUserInfo 获取用户信息

Jump to

Keyboard shortcuts

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