utils

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const ExpiresTime = time.Second * 60 * 60 * 24 * 10
View Source
const MaxPrec = 18
View Source
const (
	StdTimeFormat = "2006-01-02 15:04:05"
)

Variables

View Source
var (
	TokenExpired     = errors.New("Token is expired")
	TokenNotValidYet = errors.New("Token not active yet")
	TokenMalformed   = errors.New("That's not even a token")
	TokenInvalid     = errors.New("Couldn't handle this token:")
)
View Source
var (
	DecimalZeroMaxPrec = NewFromStringMaxPrec("0") // 0

)

Functions

func BcryptCheck

func BcryptCheck(password, hash string) bool

BcryptCheck 对比明文密码和数据库的哈希值

func BcryptHash

func BcryptHash(password string) string

BcryptHash 使用 bcrypt 对密码进行加密

func BeginOfMonth

func BeginOfMonth(t int64) int64

BeginOfMonth t时间戳所在月份,一号的时间。

func BeginOfWeek

func BeginOfWeek(t int64) int64

BeginOfWeek t时间戳所在星期,星期一的开始时间。

func NewFromString

func NewFromString(s string, prec int32) decimal.Decimal

func NewFromStringMaxPrec

func NewFromStringMaxPrec(s string) decimal.Decimal

decimal类型比较和计算的时候最好是统一指数,但是乘除会修改指数

s数字字符串

prec精度,小数位位数

func NextMonth

func NextMonth(t int64) int64

NextMonth t为每月的一号返回下一个月一号

func PrecCut

func PrecCut(v string, prec int32) string

535 -1 530 535.1234 1 535.1 535 1 535.0 535.1234 -1 530 535.1234 6 535.123400

Types

type CustomClaims

type CustomClaims struct {
	JwtContent
	jwt.RegisteredClaims
}

type JWT

type JWT struct {
	SigningKey []byte
}

func NewJWT

func NewJWT() *JWT

func (*JWT) CreateClaims

func (j *JWT) CreateClaims(baseClaims JwtContent) CustomClaims

func (*JWT) CreateToken

func (j *JWT) CreateToken(claims CustomClaims) (string, error)

创建一个token

func (*JWT) ParseToken

func (j *JWT) ParseToken(tokenString string) (*CustomClaims, error)

解析 token

type JwtContent

type JwtContent struct {
	UserID   int64
	Username string
	NickName string
}

type WrapCron

type WrapCron struct {
	C chan time.Time
	// contains filtered or unexported fields
}

func NewWrapCron

func NewWrapCron(spec string) (*WrapCron, error)

func (*WrapCron) Start

func (wc *WrapCron) Start()

Jump to

Keyboard shortcuts

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