utils

package
v1.0.28 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OneDay   = 86400000
	OneWeek  = OneDay * 7
	TwoWeek  = OneDay * 14
	OneMonth = OneDay * 30
)
View Source
const (
	MOBILE   = "^1[3456789]\\d{9}$"
	INTEGER  = "^[\\-]?[1-9]+[0-9]*$|^[0]$"
	FLOAT    = "^[\\-]?[1-9]+[\\.][0-9]+$|^[\\-]?[0][\\.][0-9]+$"
	IPV4     = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$"
	EMAIL    = "^([a-z0-9A-Z]+[-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$"
	ACCOUNT  = "^[a-zA-Z][a-zA-Z0-9_]{5,14}$"
	PASSWORD = "^.{6,18}$"
	URL      = "http(s)?://([\\w-]+\\.)+[\\w-]+(/[\\w- ./?%&=]*)?$"
	IDNO     = "(^\\d{18}$)|(^\\d{15}$)"
	PKNO     = "^1([3-8]{1})([0-9]{17})$"
	NUMBER   = "(^[1-9]([0-9]{0,29})$)|(^(0){1}$)"
	MONEY    = "(^[1-9]([0-9]{0,10})$)"
	MONEY2   = "(^[1-9]([0-9]{0,12})?(\\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\\.[0-9]([0-9])?$)"
)

Variables

This section is empty.

Functions

func Add

func Add(a, b interface{}) (string, error)

func AddStr

func AddStr(input ...interface{}) string

高性能拼接字符串

func AesDecrypt

func AesDecrypt(msg, key, iv string) ([]byte, error)

func AesEncrypt

func AesEncrypt(plantText []byte, key, iv string) (string, error)

func AnyToStr

func AnyToStr(any interface{}) string

基础类型 int uint float string bool 复杂类型 json

func Base64Decode

func Base64Decode(input interface{}) []byte

default base64 - 逆向

func Base64Encode

func Base64Encode(input interface{}) string

default base64 - 正向

func Base64URLDecode

func Base64URLDecode(input interface{}) []byte

url base64 - 逆向

func Base64URLEncode

func Base64URLEncode(input interface{}) string

url base64 - 正向

func Bytes2Str

func Bytes2Str(b []byte) string

字节数组转字符串

func CheckInt

func CheckInt(c int, vs ...int) bool

检测int数值是否在区间

func CheckInt64

func CheckInt64(c int64, vs ...int64) bool

检测int64数值是否在区间

func CheckLen

func CheckLen(o interface{}, min, max int) bool

获取并校验字符串长度

func CheckStr

func CheckStr(c string, vs ...string) bool

检测string数值是否在区间

func CheckStrLen

func CheckStrLen(str string, min, max int) bool

获取并校验字符串长度

func ClientIP

func ClientIP(req *http.Request) string

RemoteIp 返回远程客户端的 IP,如 192.168.1.1

func Cmp

func Cmp(a, b interface{}) int

a>b=1 a=b=0 a<b=-1

func CreateLocalSecretKey

func CreateLocalSecretKey(arr ...int) string

func DeepCopy added in v1.0.27

func DeepCopy(dst, src interface{}) error

深度复制对象

func Div

func Div(a, b interface{}, n int32) (string, error)

func Error

func Error(input ...interface{}) error

高性能拼接错误对象

func Float64ToInt64

func Float64ToInt64(f float64) int64

float64转int64

func FmtDiv added in v1.0.9

func FmtDiv(v string, d int64) string

func FmtZero added in v1.0.9

func FmtZero(r string) string

func GetAesIV

func GetAesIV(iv string) []byte

func GetAesKey

func GetAesKey(key string) []byte

func GetAnyDayFirstAndLast

func GetAnyDayFirstAndLast(x int64) (int64, int64)

获取x天开始和结束时间,最多30天

func GetAnyMonthFirstAndLast

func GetAnyMonthFirstAndLast(month int) (int64, int64)

获取指定月份开始和结束时间

func GetBool

func GetBool(ptr uintptr) bool

get bool value

func GetBoolArr

func GetBoolArr(ptr uintptr) []bool

get []bool value

func GetDayFirstAndLast

func GetDayFirstAndLast() (int64, int64)

获取当天开始和结束时间

func GetFloat32

func GetFloat32(ptr uintptr) float32

get float32 value

func GetFloat32Arr

func GetFloat32Arr(ptr uintptr) []float32

get []float32 value

func GetFloat64

func GetFloat64(ptr uintptr) float64

get float64 value

func GetFloat64Arr

func GetFloat64Arr(ptr uintptr) []float64

get []float64 value

func GetFmtDate

func GetFmtDate(t int64) int64

获取时间的0点

func GetInDayFirstAndLast

func GetInDayFirstAndLast(x int64) (int64, int64)

获取x天开始和当天结束时间,最多30天

func GetInt

func GetInt(ptr uintptr) int

get int value

func GetInt16

func GetInt16(ptr uintptr) int16

get int16 value

func GetInt16Arr

func GetInt16Arr(ptr uintptr) []int16

get []int16 value

func GetInt32

func GetInt32(ptr uintptr) int32

get int32 value

func GetInt32Arr

func GetInt32Arr(ptr uintptr) []int32

get []int32 value

func GetInt64

func GetInt64(ptr uintptr) int64

get int64 value

func GetInt64Arr

func GetInt64Arr(ptr uintptr) []int64

get []int64 value

func GetInt8

func GetInt8(ptr uintptr) int8

get int8 value

func GetInt8Arr

func GetInt8Arr(ptr uintptr) []int8

get []int8 value

func GetIntArr

func GetIntArr(ptr uintptr) []int

get []int value

func GetJsonBool added in v1.0.2

func GetJsonBool(b []byte, k string) bool

func GetJsonInt added in v1.0.2

func GetJsonInt(b []byte, k string) int

func GetJsonString added in v1.0.2

func GetJsonString(b []byte, k string) string

func GetLocalIP

func GetLocalIP() string

获取本机内网IP

func GetLocalSecretKey

func GetLocalSecretKey() string

func GetLocalTokenSecretKey

func GetLocalTokenSecretKey() string

func GetMonthFirstAndLast

func GetMonthFirstAndLast() (int64, int64)

获取当前月份开始和结束时间

func GetPath

func GetPath() string

获取项目绝对路径

func GetPtr

func GetPtr(v interface{}, offset uintptr) uintptr

通过指针获取对象字段位置

func GetSnowflakeNode added in v1.0.5

func GetSnowflakeNode(n int64) *snowflake.Node

func GetString

func GetString(ptr uintptr) string

get string value

func GetStringArr

func GetStringArr(ptr uintptr) []string

get []string value

func GetUUID

func GetUUID(replace ...bool) string

func GetUint

func GetUint(ptr uintptr) uint

get uint value

func GetUint16

func GetUint16(ptr uintptr) uint16

get uint16 value

func GetUint16Arr

func GetUint16Arr(ptr uintptr) []uint16

get []uint16 value

func GetUint32

func GetUint32(ptr uintptr) uint32

get uint32 value

func GetUint32Arr

func GetUint32Arr(ptr uintptr) []uint32

get []uint32 value

func GetUint64

func GetUint64(ptr uintptr) uint64

get uint64 value

func GetUint64Arr

func GetUint64Arr(ptr uintptr) []uint64

get []uint64 value

func GetUint8

func GetUint8(ptr uintptr) uint8

get uint8 value

func GetUint8Arr

func GetUint8Arr(ptr uintptr) []uint8

get []uint8 value

func GetUintArr

func GetUintArr(ptr uintptr) []uint

get []uint value

func GetWeekFirstAndLast

func GetWeekFirstAndLast() (int64, int64)

获取当前星期开始和结束时间

func HMAC_MD5

func HMAC_MD5(data, key string, useBase64 ...bool) string

HMAC-MD5加密

func HMAC_SHA1

func HMAC_SHA1(data, key string, useBase64 ...bool) string

HMAC-SHA1加密

func HMAC_SHA256

func HMAC_SHA256(data, key string, useBase64 ...bool) string

HMAC-SHA256加密

func HasStr

func HasStr(s1 string, s2 string) bool

判定指定字符串是否存在于原字符串

func InArray

func InArray(p interface{}) []interface{}

func Int2Time

func Int2Time(t int64) time.Time

时间戳转time

func IsAccount

func IsAccount(s string) bool

func IsEmail

func IsEmail(s string) bool

func IsFloat

func IsFloat(s string) bool

func IsIDNO

func IsIDNO(s string) bool

func IsIPV4

func IsIPV4(s string) bool

func IsInt

func IsInt(s string) bool

func IsMobil

func IsMobil(s string) bool

func IsMoney

func IsMoney(s string) bool

分格式

func IsMoney2

func IsMoney2(s string) bool

常规浮点格式

func IsNumber

func IsNumber(s string) bool

func IsPKNO

func IsPKNO(s string) bool

func IsPassword

func IsPassword(s string) bool

func IsURL

func IsURL(s string) bool

func JsonMarshal

func JsonMarshal(v interface{}) ([]byte, error)

对象转JSON字符串

func JsonToAny

func JsonToAny(src interface{}, target interface{}) error

对象转对象

func JsonUnmarshal

func JsonUnmarshal(data []byte, v interface{}) error

JSON字符串转对象

func Len

func Len(o interface{}) int

获取混合字符串实际长度

func LowerFirst

func LowerFirst(str string) string

65-96大写字母 97-122小写字母

func MD5

func MD5(s string, useBase64 ...bool) string

MD5加密

func MatchFilterURL

func MatchFilterURL(requestPath string, matchPattern []string) bool

func MathAbs

func MathAbs(n int64) int64

func ModRand added in v1.0.4

func ModRand(n int) int

ModRand 调用底层生成随机数,进行取模运算,性能提升10倍

func Mul

func Mul(a, b interface{}) (string, error)

func NewFloat32

func NewFloat32(b []byte) (float32, error)

byte to float32

func NewFloat64

func NewFloat64(b []byte) (float64, error)

byte to float64

func NewInt

func NewInt(b []byte) (int, error)

byte to int

func NewInt16

func NewInt16(b []byte) (int16, error)

byte to int16

func NewInt32

func NewInt32(b []byte) (int32, error)

byte to int32

func NewInt64

func NewInt64(b []byte) (int64, error)

byte to int64

func NewInt8

func NewInt8(b []byte) (int8, error)

byte to int8

func NewString

func NewString(b []byte) (string, error)

byte to string

func NewUint

func NewUint(b []byte) (uint, error)

byte to uint

func NewUint16

func NewUint16(b []byte) (uint16, error)

byte to uint16

func NewUint32

func NewUint32(b []byte) (uint32, error)

byte to uint32

func NewUint64

func NewUint64(b []byte) (uint64, error)

byte to uint64

func NewUint8

func NewUint8(b []byte) (uint8, error)

byte to uint8

func NextIID added in v1.0.5

func NextIID() int64

NextIID 获取雪花int64 ID,默认为1024区

func NextSID added in v1.0.5

func NextSID() string

NextSID 获取雪花string ID,默认为1024区

func PKCS7Padding

func PKCS7Padding(ciphertext []byte, blockSize int) []byte

func PKCS7UnPadding

func PKCS7UnPadding(plantText []byte, blockSize int) []byte

func ParseJsonBase64

func ParseJsonBase64(input interface{}, ouput interface{}) error

func RandInt

func RandInt(n int) string

func RandNonce

func RandNonce() string

func RandStr

func RandStr(n int, b ...bool) string

func ReadFile

func ReadFile(path string) ([]byte, error)

读取文件

func ReadJsonConfig

func ReadJsonConfig(conf []byte, result interface{}) error

读取JSON格式配置文件

func ReadLocalJsonConfig

func ReadLocalJsonConfig(path string, result interface{}) error

读取本地JSON配置文件

func Reverse

func Reverse(s string) string

func ReverseBase64

func ReverseBase64(s string) string

func ReverseStr

func ReverseStr(s string, x ...int) string

func SHA1

func SHA1(s string, useBase64 ...bool) string

SHA256加密

func SHA256

func SHA256(s string, useBase64 ...bool) string

SHA256加密

func SetBool

func SetBool(ptr uintptr, v bool)

set bool value

func SetBoolArr

func SetBoolArr(ptr uintptr, v []bool)

set []bool value

func SetFloat32

func SetFloat32(ptr uintptr, v float32)

set float32 value

func SetFloat32Arr

func SetFloat32Arr(ptr uintptr, v []float32)

set []float32 value

func SetFloat64

func SetFloat64(ptr uintptr, v float64)

set float32 value

func SetFloat64Arr

func SetFloat64Arr(ptr uintptr, v []float64)

set []float64 value

func SetInt

func SetInt(ptr uintptr, v int)

set int value

func SetInt16

func SetInt16(ptr uintptr, v int16)

set int16 value

func SetInt16Arr

func SetInt16Arr(ptr uintptr, v []int16)

set []int16 value

func SetInt32

func SetInt32(ptr uintptr, v int32)

set int32 value

func SetInt32Arr

func SetInt32Arr(ptr uintptr, v []int32)

set []int32 value

func SetInt64

func SetInt64(ptr uintptr, v int64)

set int64 value

func SetInt64Arr

func SetInt64Arr(ptr uintptr, v []int64)

set []int64 value

func SetInt8

func SetInt8(ptr uintptr, v int8)

set int8 value

func SetInt8Arr

func SetInt8Arr(ptr uintptr, v []int8)

set []int8 value

func SetIntArr

func SetIntArr(ptr uintptr, v []int)

set []int value

func SetString

func SetString(ptr uintptr, v string)

set string value

func SetStringArr

func SetStringArr(ptr uintptr, v []string)

set []string value

func SetUint

func SetUint(ptr uintptr, v uint)

set uint value

func SetUint16

func SetUint16(ptr uintptr, v uint16)

set uint16 value

func SetUint16Arr

func SetUint16Arr(ptr uintptr, v []uint16)

set []uint16 value

func SetUint32

func SetUint32(ptr uintptr, v uint32)

set uint32 value

func SetUint32Arr

func SetUint32Arr(ptr uintptr, v []uint32)

set []uint32 value

func SetUint64

func SetUint64(ptr uintptr, v uint64)

set uint64 value

func SetUint64Arr

func SetUint64Arr(ptr uintptr, v []uint64)

set []uint64 value

func SetUint8

func SetUint8(ptr uintptr, v uint8)

set uint value

func SetUint8Arr

func SetUint8Arr(ptr uintptr, v []uint8)

set []uint8 value

func SetUintArr

func SetUintArr(ptr uintptr, v []uint)

set []uint value

func Shift

func Shift(input interface{}, ln int, fz bool) string

保留小数位

func ShiftN

func ShiftN(a interface{}, n int32) (string, error)

func StartWait

func StartWait(msg string)

无限等待

func Str2Bytes

func Str2Bytes(s string) []byte

字符串转字节数组

func Str2Date

func Str2Date(s string) (int64, error)

格式字符串转时间戳/毫秒

func Str2Time

func Str2Time(s string) (int64, error)

格式字符串转时间戳/毫秒

func StrToBool

func StrToBool(str string) (bool, error)

string to bool

func StrToFloat

func StrToFloat(str string) (float64, error)

转换成小数

func StrToInt

func StrToInt(str string) (int, error)

string to int

func StrToInt16

func StrToInt16(str string) (int16, error)

string to int16

func StrToInt32

func StrToInt32(str string) (int32, error)

string to int32

func StrToInt64

func StrToInt64(str string) (int64, error)

string to int64

func StrToInt8

func StrToInt8(str string) (int8, error)

string to int8

func Sub

func Sub(a, b interface{}) (string, error)

func Substr

func Substr(str string, start int, end int) string

截取字符串 start 起点下标 end 结束下标

func Time2DateStr

func Time2DateStr(t int64) string

时间戳转格式字符串/毫秒

func Time2Str

func Time2Str(t int64) string

时间戳转格式字符串/毫秒

func ToJsonBase64

func ToJsonBase64(input interface{}) (string, error)

func UnixMilli added in v1.0.5

func UnixMilli() int64

获取当前时间/毫秒

func UnixNano added in v1.0.4

func UnixNano() int64

UnixNano 直接调用底层方法比time.Now()性能提升1倍

func UnixSecond added in v1.0.4

func UnixSecond() int64

获取当前时间/秒

func UpperFirst

func UpperFirst(str string) string

65-96大写字母 97-122小写字母

func ValidPattern

func ValidPattern(content, pattern string) bool

Types

This section is empty.

Directories

Path Synopsis
Multiprecision decimal numbers.
Multiprecision decimal numbers.
Package snowflake provides a very simple Twitter snowflake generator and parser.
Package snowflake provides a very simple Twitter snowflake generator and parser.

Jump to

Keyboard shortcuts

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