utils

package
v0.0.0-...-592b0ac Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2021 License: Apache-2.0 Imports: 33 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 CheckPasswordLever

func CheckPasswordLever(ps string) int32

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

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

func CheckUserName

func CheckUserName(name string) error

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

func Convert

func Convert(src interface{}, dst interface{}) interface{}

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

func CreateToken

func CreateToken(secretKey string, claims CustomClaims) (string, error)

创建一个token

func DecimalToAny

func DecimalToAny(num, n int64) string

10进制转任意进制

func FuncName

func FuncName() string

获取正在运行的函数名

func GetIP

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

@Summary 获取真实的源ip

func GetJwtToken

func GetJwtToken(secretKey string, iat, seconds, uid int64) (string, error)

func GetLoginNameType

func GetLoginNameType(userName string) def.UserInfoType

func GetPassword

func GetPassword(length int, level int) string

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

func GetPwdBase64

func GetPwdBase64(length int) string

func HandleThrow

func HandleThrow(p interface{})

func HmacSha1

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

func HmacSha256

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

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 MatchIP

func MatchIP(ip, iprange string) bool

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

func RefreshToken

func RefreshToken(tokenString string, secretKey string) (string, error)

更新token

func SetVal

func SetVal(key interface{}, src, dst interface{}) (num int)

返回修改的数量

func SetVals

func SetVals(src interface{}, dst interface{}) (num int)

func ToLen

func ToLen(src string, length int) string

func Unmarshal

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

Types

type CheckExp

type CheckExp interface {
	IsTimeOut() bool
}

type CustomClaims

type CustomClaims struct {
	Uid int64
	jwt.StandardClaims
}

Custom claims structure

func ParseToken

func ParseToken(tokenString string, secretKey string) (*CustomClaims, *errors.CodeError)

解析 token

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]

Jump to

Keyboard shortcuts

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