utils

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: AGPL-3.0 Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResultCodeSystemError = 99 // 系统级别错误
	ResultCodeAuth        = 2  // 权限错误
	ResultCodeError       = 1  // 常用错误
	ResultCodeSuccess     = 0  // 成功
)
View Source
const PageSize = 10

Variables

View Source
var (
	Validate      *validator.Validate
	ValidateTrans ut.Translator
)

表单验证 https://github.com/go-playground/validator

Functions

func AesDecrypt

func AesDecrypt(text string, key []byte) (string, error)

func AesEncrypt

func AesEncrypt(text string, key []byte) (string, error)

func Base64StdDecode

func Base64StdDecode(s string) string

Base64StdDecode decode a base64 encoded string. Play: https://go.dev/play/p/RWQylnJVgIe

func Base64StdEncode

func Base64StdEncode(s string) string

Base64StdEncode encode string with base64 encoding. Play: https://go.dev/play/p/VOaUyQUreoK

func Bind

func Bind(source interface{}, target interface{}) error

Bind 绑定结构体

func BitsToSubNetMask

func BitsToSubNetMask(maskBits int) (string, error)

BitsToSubNetMask 将掩码位数转换为子网掩码

func Byte2Map

func Byte2Map(b []byte) (map[string]interface{}, error)

func CalculateNetwork

func CalculateNetwork(ipAddr, subnetMask string) (string, error)

CalculateNetwork 根据给定的IP地址和子网掩码计算网络地址

func ContainsInt64

func ContainsInt64(is []int64, i int64) bool

func CurrentDate

func CurrentDate() string

func CurrentDateByPlace

func CurrentDateByPlace(place string) string

func CurrentTime

func CurrentTime() string

func CurrentTimeAppointDay

func CurrentTimeAppointDay(t time.Time) string

func CurrentTimeDay

func CurrentTimeDay() string

func DecryptByAes

func DecryptByAes(data string, key []byte) (string, error)

DecryptByAes base64解码后 Aes 解密

func DesDecrypt

func DesDecrypt(text string, key []byte) (string, error)

DesDecrypt

func DesDecryptCBC

func DesDecryptCBC(text string, key []byte) (string, error)

DesDecryptCBC

func DesEncrypt

func DesEncrypt(text string, key []byte) (string, error)

DesEncrypt DES加密,秘钥必须是64位,所以key必须是长度为8的byte数组

func DesEncryptCBC

func DesEncryptCBC(text string, key []byte) (string, error)

DesEncryptCBC

func DetectTcpPort

func DetectTcpPort(ip string, port int, timeout time.Duration) bool

DetectTcpPort 检测Tcp端口是否开通

func EachMapSort

func EachMapSort(eachMap interface{}, eachFunc interface{}) error

func EncryptByAes

func EncryptByAes(data string, key []byte) (string, error)

EncryptByAes Aes加密 后 base64

func FormatDate

func FormatDate(t time.Time) string

func FormatMonth

func FormatMonth(t time.Time) string

func FormatMonthChinese

func FormatMonthChinese(t time.Time) string

func FormatTime

func FormatTime(t time.Time) string

func GetInterfaceFiledValue

func GetInterfaceFiledValue(v interface{}, fieldName string) reflect.Value

func GetLinesFromBuffer

func GetLinesFromBuffer(buf *bytes.Buffer) []string

func GetPageIndex

func GetPageIndex(pageIndex int) int

func GetPageNumber

func GetPageNumber(count int64, pageSize int) int

func GetPageSize

func GetPageSize(pageSize int) int

func GetRemoteAddr

func GetRemoteAddr(rc *app.RequestContext) string

GetRemoteAddr 获取远程IP

func GetSelfIps

func GetSelfIps() map[string]map[string]string

func GetSelfPath

func GetSelfPath() string

func GetSelfPathFull

func GetSelfPathFull() string

func GetSelfV4IFaceFirst

func GetSelfV4IFaceFirst() string

func GetSelfV4IpFirst

func GetSelfV4IpFirst(iFace ...string) string

func GetSelfV4Ips

func GetSelfV4Ips() map[string]string

func GetSelfV6IFaceFirst

func GetSelfV6IFaceFirst() string

func GetSelfV6IpFirst

func GetSelfV6IpFirst(iFace ...string) string

func GetSelfV6Ips

func GetSelfV6Ips() map[string]string

func HmacMd5

func HmacMd5(str, key string) string

HmacMd5 return the hmac hash of string use md5. Play: https://go.dev/play/p/uef0q1fz53I

func HmacMd5WithBase64

func HmacMd5WithBase64(data, key string) string

HmacMd5WithBase64 return the hmac hash of string use md5 with base64. https://go.dev/play/p/UY0ng2AefFC

func HmacSha1

func HmacSha1(str, key string) string

HmacSha1 return the hmac hash of string use sha1. Play: https://go.dev/play/p/1UI4oQ4WXKM

func HmacSha1WithBase64

func HmacSha1WithBase64(str, key string) string

HmacSha1WithBase64 return the hmac hash of string use sha1 with base64. Play: https://go.dev/play/p/47JmmGrnF7B

func HmacSha256

func HmacSha256(str, key string) string

HmacSha256 return the hmac hash of string use sha256. Play: https://go.dev/play/p/HhpwXxFhhC0

func HmacSha256WithBase64

func HmacSha256WithBase64(str, key string) string

HmacSha256WithBase64 return the hmac hash of string use sha256 with base64. Play: https://go.dev/play/p/EKbkUvPTLwO

func HmacSha512

func HmacSha512(str, key string) string

HmacSha512 return the hmac hash of string use sha512. Play: https://go.dev/play/p/59Od6m4A0Ud

func HmacSha512WithBase64

func HmacSha512WithBase64(str, key string) string

HmacSha512WithBase64 return the hmac hash of string use sha512 with base64. Play: https://go.dev/play/p/c6dSe3E2ydU

func ID

func ID() int64

func IDString

func IDString() string

func IntConvertToIpAddress

func IntConvertToIpAddress(ipInt int) (string, error)

IntConvertToIpAddress 将整数转换为IP地址

func InterfaceToStruct

func InterfaceToStruct(out interface{}, in interface{}) error

func IpAddressConvertToInt

func IpAddressConvertToInt(ip string) (int, error)

IpAddressConvertToInt 将IP地址转换为整数

func IsUuid

func IsUuid(obj interface{}) bool

func IsValidIP

func IsValidIP(ipAddr string) bool

IsValidIP 检测IP地址是否合法

func IsValidPort

func IsValidPort(port string) (int, error)

IsValidPort 检测端口是否合法

func IsValidURL

func IsValidURL(u string) bool

IsValidURL 检测给定字符串是否是一个合法的URL。

func MakeInstanceFromSlice

func MakeInstanceFromSlice(v interface{}) (i interface{}, err error)

func MapStringValues

func MapStringValues(m map[string]string) (v []string)

func MatchString

func MatchString(src, pattern string) bool

MatchString 检查正则表达式是否与给定的源字符串匹配。

func Md5Byte

func Md5Byte(data []byte) string

Md5Byte return the md5 string of byte slice. Play: https://go.dev/play/p/suraalH8lyC

func Md5ByteWithBase64

func Md5ByteWithBase64(data []byte) string

Md5ByteWithBase64 return the md5 string of byte slice with base64. Play: https://go.dev/play/p/Tcb-Z7LN2ax

func Md5File

func Md5File(filename string) (string, error)

Md5File return the md5 value of file.

func Md5String

func Md5String(s string) string

Md5String return the md5 value of string. Play: https://go.dev/play/p/1bLcVetbTOI

func Md5StringWithBase64

func Md5StringWithBase64(s string) string

Md5StringWithBase64 return the md5 value of string with base64. Play: https://go.dev/play/p/Lx4gH7Vdr5_y

func MustBool

func MustBool(value interface{}) bool

func MustBoolArray

func MustBoolArray(value interface{}) (resArray []bool)

尽最大努力将目标转换为[]bool,失败会panic

func MustExplodeStructField

func MustExplodeStructField(array interface{}, field string) (explodeArray []interface{})

func MustFloat32

func MustFloat32(value interface{}) (res float32)

func MustFloat32Array

func MustFloat32Array(value interface{}) (resArray []float32)

尽最大努力将目标转换为[]float32,失败会panic

func MustFloat64

func MustFloat64(value interface{}) (res float64)

func MustFloat64Array

func MustFloat64Array(value interface{}) (resArray []float64)

尽最大努力将目标转换为[]float64,失败会panic

func MustInt

func MustInt(value interface{}) (res int)

强制转换为int,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustInt16

func MustInt16(value interface{}) (res int16)

强制转换为int16,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int16 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustInt16Array

func MustInt16Array(value interface{}) (resArray []int16)

尽最大努力将目标转换为[]int16,失败会panic

func MustInt32

func MustInt32(value interface{}) (res int32)

强制转换为int32,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int32 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustInt32Array

func MustInt32Array(value interface{}) (resArray []int32)

尽最大努力将目标转换为[]int32,失败会panic

func MustInt64

func MustInt64(value interface{}) (res int64)

强制转换为int64,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int64 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustInt64Array

func MustInt64Array(value interface{}) (resArray []int64)

尽最大努力将目标转换为[]int64,失败会panic

func MustInt8

func MustInt8(value interface{}) (res int8)

强制转换为int8,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int8 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustInt8Array

func MustInt8Array(value interface{}) (resArray []int8)

尽最大努力将目标转换为[]int8,失败会panic

func MustIntArray

func MustIntArray(value interface{}) (resArray []int)

尽最大努力将目标转换为[]int,失败会panic

func MustInterfaceArray

func MustInterfaceArray(array interface{}) []interface{}

func MustJson

func MustJson(i interface{}) []byte

func MustJsonPrettyString

func MustJsonPrettyString(i interface{}) string

func MustJsonString

func MustJsonString(i interface{}) string

func MustMapStringInterfaceRecursions

func MustMapStringInterfaceRecursions(leafMap interface{}) map[string]interface{}

把map转成map[string]interface{},key的值使用MustString计算。 如果子项中也有map,则继续递归执行直到全部转换为map[string]interface{} 如果子项有[]interface{},则要继续判定slice的元素中的类型 常用于各种xml\yaml\json转换为map的结果的统一处理。

func MustMapStringInterfaceRecursionsInArrayInterface

func MustMapStringInterfaceRecursionsInArrayInterface(leafAry interface{}) []interface{}

协助处理[]interface{}中的map[interface{}]interface{}为map[string]interface{}

func MustString

func MustString(value interface{}) string

强制转换一个对象为string

func MustStringArray

func MustStringArray(array interface{}) (resArray []string)

强转一个字符串数组

func MustUint

func MustUint(value interface{}) (res uint)

强制转换为uint,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint;空字符串会转化为0. float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustUint16

func MustUint16(value interface{}) (res uint16)

强制转换为uint16,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint16 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustUint16Array

func MustUint16Array(value interface{}) (resArray []uint16)

尽最大努力将目标转换为[]uint16,失败会panic

func MustUint32

func MustUint32(value interface{}) (res uint32)

强制转换为uint32,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint32 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustUint32Array

func MustUint32Array(value interface{}) (resArray []uint32)

尽最大努力将目标转换为[]uint32,失败会panic

func MustUint64

func MustUint64(value interface{}) (res uint64)

强制转换为uint64,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint64 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustUint64Array

func MustUint64Array(value interface{}) (resArray []uint64)

尽最大努力将目标转换为[]uint64,失败会panic

func MustUint8

func MustUint8(value interface{}) (res uint8)

强制转换为uint8,失败则panic string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint8 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func MustUint8Array

func MustUint8Array(value interface{}) (resArray []uint8)

尽最大努力将目标转换为[]uint8,失败会panic

func MustUintArray

func MustUintArray(value interface{}) (resArray []uint)

尽最大努力将目标转换为[]uint,失败会panic

func NowTimeMillisecond

func NowTimeMillisecond() string

NowTimeMillisecond 获取当前时间,格式为:2006-01-02 15:04:05.0000

func NowTimeSecond

func NowTimeSecond() string

NowTimeSecond 获取当前时间,格式为:2006-01-02 15:04:05

func Obj2ListMap

func Obj2ListMap(obj interface{}) ([]map[string]interface{}, error)

func Obj2ListMapString

func Obj2ListMapString(obj interface{}) ([]map[string]string, error)

func Obj2Map

func Obj2Map(obj interface{}) (map[string]interface{}, error)

func Obj2MapString

func Obj2MapString(obj interface{}) (map[string]string, error)

func ParseDate

func ParseDate(date string) (time.Time, error)

func ParseTime

func ParseTime(date string) (time.Time, error)

func Ping

func Ping(ipAddr string, timeout time.Duration) bool

Ping 对目的地址发起ping检测icmp是否通畅(只支持ipv4)

func PortCheck

func PortCheck(host string, port int) bool

PortCheck 检查端口是否可用,可用-true 不可用-false

func ReTry

func ReTry(callback func() bool, times int, step time.Duration)

func RemoveFirstString

func RemoveFirstString(slice []string) []string

RemoveFirstString 从字符串数组切片里移除第一个元素

func RemoveItemsContainingSubstring

func RemoveItemsContainingSubstring(arr []string, substr string) []string

RemoveItemsContainingSubstring 从字符串数组切片里移除包含substr字符串的项并移除连续空格字符

func RemoveItemsNotContainingSubstring

func RemoveItemsNotContainingSubstring(arr []string, substr string) []string

RemoveItemsNotContainingSubstring 从字符串数组切片里移除不包含substr字符串的项并移除连续空格字符

func RemoveMatchString

func RemoveMatchString(slice []string, pattern string, method int) []string

RemoveMatchString 按正则表达式移除字符串数组切片中的元素 method为1则移除匹配项 method为2则移除不匹配项

func RemoveMultiSpaces

func RemoveMultiSpaces(str string) string

RemoveMultiSpaces 从字符串中移除多个连续空格字符

func RemoveTextWithinMatch

func RemoveTextWithinMatch(str string, pattern string, method int) string

RemoveTextWithinMatch 按正则表达式移除字符串中的行 method为1则移除匹配项 method为2则移除不匹配项

func RemoveTextWithinParens

func RemoveTextWithinParens(str string) string

RemoveTextWithinParens 从字符串中删除括号内的文本。

func Result

func Result(rc *app.RequestContext, errno int, errmsg string, data interface{})

func ResultAuthError

func ResultAuthError(rc *app.RequestContext)

func ResultError

func ResultError(rc *app.RequestContext, errMsg string)

func ResultErrorData

func ResultErrorData(rc *app.RequestContext, errMsg string, data interface{})

func ResultSuccess

func ResultSuccess(rc *app.RequestContext, msg string, data interface{})

func ResultSuccessData

func ResultSuccessData(rc *app.RequestContext, data interface{})

func ResultSuccessMsg

func ResultSuccessMsg(rc *app.RequestContext, msg string)

func ResultSystemError

func ResultSystemError(rc *app.RequestContext, errMsg string)

func RunningOs

func RunningOs(osName ...string) string

func Sha1

func Sha1(str string) string

Sha1 return the sha1 value (SHA-1 hash algorithm) of string. Play: https://go.dev/play/p/_m_uoD1deMT

func Sha1WithBase64

func Sha1WithBase64(str string) string

Sha1WithBase64 return the sha1 value (SHA-1 hash algorithm) of base64 string. Play: https://go.dev/play/p/fSyx-Gl2l2-

func Sha256

func Sha256(str string) string

Sha256 return the sha256 value (SHA256 hash algorithm) of string. Play: https://go.dev/play/p/tU9tfBMIAr1

func Sha256WithBase64

func Sha256WithBase64(str string) string

Sha256WithBase64 return the sha256 value (SHA256 hash algorithm) of base64 string. Play: https://go.dev/play/p/85IXJHIal1k

func Sha512

func Sha512(str string) string

Sha512 return the sha512 value (SHA512 hash algorithm) of string. Play: https://go.dev/play/p/3WsvLYZxsHa

func Sha512WithBase64

func Sha512WithBase64(str string) string

Sha512WithBase64 return the sha512 value (SHA512 hash algorithm) of base64 string. Play: https://go.dev/play/p/q_fY2rA-k5I

func String2Map

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

func String2MapList

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

func StringEndWith

func StringEndWith(str, suffix string) bool

StringEndWith 检查字符串是否以指定的后缀结尾。

func StringEndWithIgnoreCase

func StringEndWithIgnoreCase(str, suffix string) bool

StringEndWithIgnoreCase 检查字符串是否以指定的后缀结尾,忽略大小写。

func StringIsEmpty

func StringIsEmpty(str string) bool

StringIsEmpty 检查字符串是否为空。

func StringIsInt

func StringIsInt(str string) (int, bool)

StringIsInt 检查字符串是否是一个整数。

func StringIsInt64

func StringIsInt64(str string) (int64, bool)

StringIsInt64 检查字符串是否是一个64位整数。

func StringStartWith

func StringStartWith(str, prefix string) bool

StringStartWith 检查字符串是否以指定的前缀开头。

func StringStartWithIgnoreCase

func StringStartWithIgnoreCase(str, prefix string) bool

StringStartWithIgnoreCase 检查字符串是否以指定的前缀开头,忽略大小写。

func SubNetMaskToBits

func SubNetMaskToBits(subnetMask string) (int, error)

SubNetMaskToBits 将子网掩码转换为掩码位数

func ToArrayMapStr

func ToArrayMapStr(m []map[string]interface{}) (string, error)

func ToArrayMapString

func ToArrayMapString(maps []map[string]interface{}) []map[string]string

func ToBool

func ToBool(value interface{}) (res bool, err error)

字符串中将"1", "t", "T", "true", "TRUE", "True"转为true 将"0", "f", "F", "false", "FALSE", "False", ""转为false,空字符串也转为false 数字中仅支持将0转为false,1转为true。

func ToBoolArray

func ToBoolArray(value interface{}) (resArray []bool, err error)

尽最大努力将目标转换为[]int

func ToExplodeStructField

func ToExplodeStructField(array interface{}, field string) (explodeArray []interface{}, err error)

把数组中的各个元素的指定filed取出来放到一个数组中 要求Array所有元素都是同一种类型,虽然支持指针混用但建议尽可能避免。 ary := []interface{}{foo{ID: 1, Field: "foo1"}, &foo{ID: 2, Field: "foo22"}} fieldAry := Explode(ary,"Field") // []interface{}{"foo1","foo22"}

func ToFload64

func ToFload64(value string) (float64, error)

func ToFloat32

func ToFloat32(value interface{}) (res float32, err error)

尽最大努力将一个值转为float32类型的数据 string会按顺序尝试将数据解析为float64\uint64\bool,然后再转换为float64 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToFloat32Array

func ToFloat32Array(value interface{}) (resArray []float32, err error)

尽最大努力将目标转换为[]float32

func ToFloat64

func ToFloat64(value interface{}) (res float64, err error)

尽最大努力将一个值转为float64类型的数据 string会按顺序尝试将数据解析为float64\uint64\bool,然后再转换为float64 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToFloat64Array

func ToFloat64Array(value interface{}) (resArray []float64, err error)

尽最大努力将目标转换为[]float64

func ToInt

func ToInt(value interface{}) (res int, err error)

尽最大努力将一个值转为int类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToInt16

func ToInt16(value interface{}) (res int16, err error)

尽最大努力将一个值转为int16类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int16 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToInt16Array

func ToInt16Array(value interface{}) (resArray []int16, err error)

尽最大努力将目标转换为[]int16

func ToInt32

func ToInt32(value interface{}) (res int32, err error)

尽最大努力将一个值转为int32类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int32 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToInt32Array

func ToInt32Array(value interface{}) (resArray []int32, err error)

尽最大努力将目标转换为[]int32

func ToInt64

func ToInt64(value interface{}) (res int64, err error)

尽最大努力将一个值转为int64类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int64 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToInt64Array

func ToInt64Array(value interface{}) (resArray []int64, err error)

尽最大努力将目标转换为[]int64

func ToInt8

func ToInt8(value interface{}) (res int8, err error)

尽最大努力将一个值转为int8类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为int8 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToInt8Array

func ToInt8Array(value interface{}) (resArray []int8, err error)

尽最大努力将目标转换为[]int8

func ToIntArray

func ToIntArray(value interface{}) (resArray []int, err error)

尽最大努力将目标转换为[]int

func ToInterfaceArray

func ToInterfaceArray(array interface{}) ([]interface{}, error)

func ToInterfaceByte

func ToInterfaceByte(m interface{}) []byte

func ToMapByte

func ToMapByte(m map[string]interface{}) []byte

func ToMapStr

func ToMapStr(m map[string]interface{}) (string, error)

func ToMapString

func ToMapString(m map[string]interface{}) map[string]string

func ToObjStr

func ToObjStr(o interface{}) string

func ToString

func ToString(value interface{}) string

转换一个对象为string

func ToStringArray

func ToStringArray(value interface{}) ([]string, error)

尝试一个字符串数组

func ToStringArrayInt64

func ToStringArrayInt64(value, sep string) (arr []int64)

尝试一个字符串数组

func ToUint

func ToUint(value interface{}) (res uint, err error)

尽最大努力将一个值转为uint类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToUint16

func ToUint16(value interface{}) (res uint16, err error)

尽最大努力将一个值转为uint16类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint16 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToUint16Array

func ToUint16Array(value interface{}) (resArray []uint16, err error)

尽最大努力将目标转换为[]uint16

func ToUint32

func ToUint32(value interface{}) (res uint32, err error)

尽最大努力将一个值转为uint32类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint32 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToUint32Array

func ToUint32Array(value interface{}) (resArray []uint32, err error)

尽最大努力将目标转换为[]uint32

func ToUint64

func ToUint64(value interface{}) (res uint64, err error)

尽最大努力将一个值转为uint64类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint64 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToUint64Array

func ToUint64Array(value interface{}) (resArray []uint64, err error)

尽最大努力将目标转换为[]uint64

func ToUint8

func ToUint8(value interface{}) (res uint8, err error)

尽最大努力将一个值转为uint8类型的数据 string会按顺序尝试将数据解析为int64\uint64\float64\bool,然后再转换为uint8 float会抹去小数 uint8~64、int8~64都会做默认的转换 bool类型的数据,true-1;false-0

func ToUint8Array

func ToUint8Array(value interface{}) (resArray []uint8, err error)

尽最大努力将目标转换为[]uint8

func ToUintArray

func ToUintArray(value interface{}) (resArray []uint, err error)

尽最大努力将目标转换为[]uint

func TransTo62

func TransTo62(id int64) string

将十进制转换为62进制 0-9a-zA-Z 六十二进制

func TrimLeadingCharacter

func TrimLeadingCharacter(str, character string) string

TrimLeadingCharacter 从字符串中删除前导字符。

func TrimLeadingCharacterIgnoreCase

func TrimLeadingCharacterIgnoreCase(str, character string) string

TrimLeadingCharacterIgnoreCase 从字符串中删除前导字符,忽略大小写。

func TrimTrailingCharacter

func TrimTrailingCharacter(str, character string) string

TrimTrailingCharacter 从字符串中删除尾随字符。

func TrimTrailingCharacterIgnoreCase

func TrimTrailingCharacterIgnoreCase(str, character string) string

TrimTrailingCharacterIgnoreCase 从字符串中删除尾随字符,忽略大小写。

func UuidGenerate

func UuidGenerate() string

func ValidateStruct

func ValidateStruct(s interface{}) error

func XOR

func XOR(plain string, key []byte) string

XOR 异或运算加解密

Types

type Count

type Count struct {
	Count int64
}

type JsonTime

type JsonTime time.Time

func (JsonTime) MarshalJSON

func (this JsonTime) MarshalJSON() ([]byte, error)

实现它的json序列化方法

type PageData

type PageData struct {
	PageIndex  int         `json:"pageNo"`
	PageSize   int         `json:"pageSize"`
	PageNumber int         `json:"pageNum"`
	Count      int64       `json:"totalCount"`
	Data       interface{} `json:"data"`
}

type PageParam

type PageParam struct {
	PageIndex int `json:"pageNo"`
	PageSize  int `json:"pageSize"`
}

type PageTable

type PageTable struct {
	Fields    string
	Table     string
	Where     string
	PageIndex int
	PageSize  int
	Order     string
	GroupBy   string
}

type PhoneData

type PhoneData struct {
	Model      string `csv:"model"`
	Dtype      string `csv:"dtype"`
	Brand      string `csv:"brand"`
	BrandTitle string `csv:"brand_title"`
	Code       string `csv:"code"`
	CodeAlias  string `csv:"code_alias"`
	ModelName  string `csv:"model_name"`
	VerName    string `csv:"ver_name"`
}

type RandID

type RandID struct {
	// contains filtered or unexported fields
}

func NewRandID

func NewRandID() *RandID

func (*RandID) NextId

func (id *RandID) NextId() int64

type UserAgentRes

type UserAgentRes struct {
	OSName     string //操作系统名称
	OSVersion  string //操作系统版本
	PhoneBrand string //手机品牌
	PhoneModel string //手机型号
}

func GetUserAgent

func GetUserAgent(userAgent string) UserAgentRes

GetUserAgent 获取用户设备信息获取手机型号等信息

Jump to

Keyboard shortcuts

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