utils

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2023 License: AGPL-3.0 Imports: 38 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToDecimal

func AnyToDecimal(num string, n int) int64

任意进制转10进制

func AnyToNullString added in v0.3.1

func AnyToNullString(in any) sql.NullString

func CheckPasswordLever

func CheckPasswordLever(ps string) int32

检测密码是否符合规范 需要至少8位 并且需要包含数字和字母

密码强度必须为字⺟⼤⼩写+数字+符号,9位以上

func CheckUserName

func CheckUserName(name string) error

检测用户名是否符合规范 只可以使用字母数字及下划线 最多30个字符

func Convert

func Convert(src any, dst any) any

@in src 赋值的数据源 @in dst 赋值对象的结构体 @out dst类型的结构体

func Decimal

func Decimal[valueType constraints.Float](value valueType, n int) valueType

保留n位小数

func DecimalToAny

func DecimalToAny(num, n int64) string

10进制转任意进制

func Fmt

func Fmt(v any) string

Fmt 将结构以更方便看的方式打印出来

func FuncName

func FuncName() string

获取正在运行的函数名

func GetDeadLine

func GetDeadLine(ctx context.Context, defaultDeadLine time.Time) time.Time

func GetIP

func GetIP(r *http.Request) (string, error)

@Summary 获取真实的源ip

func GetMonthDays

func GetMonthDays(years int, month time.Month) int

GetMonthDays 获取指定年月的天数

func GetNodeID

func GetNodeID(cache cache.ClusterConf, svrName string) int64

func GetNullTime

func GetNullTime(time sql.NullTime) int64

func GetPositionValue added in v0.3.0

func GetPositionValue(position string) (float64, float64)

position 格式: POINT(100.101 50.894)

func GetRandomBase64 added in v0.3.0

func GetRandomBase64(length int) string

func GetSubDay

func GetSubDay(base time.Time, cmp time.Time) int64

GetSubDay 比较两个时间戳差的天数

func HandleThrow

func HandleThrow(ctx context.Context, p any)

func HmacSha1

func HmacSha1(data string, secret []byte) string

func HmacSha256

func HmacSha256(data string, secret []byte) string

func IndexN added in v0.3.0

func IndexN(src string, c byte, n int) int

从目标串src中查找第n个目标字符c所在位置下标

func Ip2binary

func Ip2binary(ip string) string

func IsEmail

func IsEmail(email string) bool

func IsMobile

func IsMobile(mobile string) bool

识别手机号码

func MD5V

func MD5V(str []byte) string

func MakePwd

func MakePwd(pwd string, uid int64, isMd5 bool) string

将密码的md5和uid进行md5

func MarshalNoErr added in v0.3.1

func MarshalNoErr(v any) string

func MatchIP

func MatchIP(ip, iprange string) bool

测试IP地址和地址端是否匹配 变量ip为字符串,例子"192.168.56.4" iprange为地址端"192.168.56.64/26"

func Random added in v0.3.0

func Random(length int, level int) string

@in len 密码的长度 @in level 密码的强度级别 0:包含数字和字母 1:包含数字字母和特殊字符

func Recover

func Recover(ctx context.Context)

func SetToSlice added in v0.3.0

func SetToSlice[t constraints.Ordered](in map[t]struct{}) (ret []t)

func SetVal

func SetVal(key any, src, dst any) (num int)

返回修改的数量

func SetVals

func SetVals(src any, dst any) (num int)

func SliceIn added in v0.3.1

func SliceIn[t comparable](in t, cmp ...t) bool

func SqlNullStringToAny added in v0.3.1

func SqlNullStringToAny(in sql.NullString, ret any) error

func Sum

func Sum[addT CanAdd](datas ...addT) (sum addT)

func TimeToInt64

func TimeToInt64(t time.Time) int64

func ToLen

func ToLen(src string, length int) string

func ToMMddHHSS

func ToMMddHHSS(timeStamp int64) string

转换为07-02 01:02 这种格式

func ToNullString

func ToNullString(val *wrappers.StringValue) *string

func ToRpcNullDouble added in v0.3.0

func ToRpcNullDouble(val *float64) *wrappers.DoubleValue

func ToRpcNullString

func ToRpcNullString(val *string) *wrappers.StringValue

func ToYYMMdd

func ToYYMMdd(timeStamp int64) string

转换为07-02 01:02 这种格式

func ToYYMMddHHSS

func ToYYMMddHHSS(timeStamp int64) string

转换为07-02 01:02 这种格式

func TraceIdFromContext

func TraceIdFromContext(ctx context.Context) string

func Unmarshal

func Unmarshal(data []byte, v any) error

Types

type CanAdd

type CanAdd interface {
	constraints.Integer | constraints.Float
}

type CheckExp

type CheckExp interface {
	IsTimeOut() bool
}

type ExpMap

type ExpMap struct {
	Map sync.Map
}

带过期时间的sync.map

func NewExpMap

func NewExpMap(checkTime time.Duration) *ExpMap

type SnowFlake

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

func NewSnowFlake

func NewSnowFlake(mId int64) *SnowFlake
var Snow = &SnowFlake{
	lastTime: time.Now().UnixNano() / 1000000,
	machineID:1,
}

func (*SnowFlake) GetMachineId

func (c *SnowFlake) GetMachineId() int64

获取机器id

func (*SnowFlake) GetSnowflakeId

func (c *SnowFlake) GetSnowflakeId() (id int64)

获取雪花 返回值 id:自增id ts:生成该id的毫秒时间戳

func (*SnowFlake) MilliSecondToTime

func (c *SnowFlake) MilliSecondToTime(milliSecond int64) (t time.Time)

毫秒转换成time

func (*SnowFlake) MillisecondToTimeDb

func (c *SnowFlake) MillisecondToTimeDb(ts int64) string

毫秒转换成"2006-01-02 15:04:05.999"

func (*SnowFlake) MillisecondToTimeTz

func (c *SnowFlake) MillisecondToTimeTz(ts int64) string

毫秒转换成"20060102T150405.999Z"

func (*SnowFlake) ParseId

func (c *SnowFlake) ParseId(id int64) (milliSecond, mId, sn int64)

解析雪花(id) 返回值 milliSecond:毫秒数 mId:机器id sn:序列号

func (*SnowFlake) SetMachineId

func (c *SnowFlake) SetMachineId(mId int64)

设置机器id,默认为0,范围[0,255]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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