remove jwt
This commit is contained in:
parent
024a0e5e96
commit
ddd2413386
3
init.go
3
init.go
@ -24,8 +24,6 @@ var (
|
||||
Project *project
|
||||
// Array 数组操作
|
||||
Array *array
|
||||
// JWT ...
|
||||
JWT *ownJwt
|
||||
// Console 控制台输出数据
|
||||
Console *console
|
||||
// PinYin 汉字转拼音
|
||||
@ -41,7 +39,6 @@ func init() {
|
||||
Calculate = &calculate{}
|
||||
Project = &project{}
|
||||
Array = &array{}
|
||||
JWT = &ownJwt{}
|
||||
Console = &console{}
|
||||
PinYin = &pinYin{}
|
||||
}
|
||||
|
66
jwt.go
66
jwt.go
@ -1,66 +0,0 @@
|
||||
// Package util ...
|
||||
//
|
||||
// Description : go-jwt具体实现
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 2023-02-11 20:09
|
||||
package util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/dgrijalva/jwt-go/v4"
|
||||
)
|
||||
|
||||
type ownJwt struct {
|
||||
}
|
||||
|
||||
type MyClaims struct {
|
||||
jwt.StandardClaims
|
||||
}
|
||||
|
||||
// Generate 生成 token
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:13 2023/2/11
|
||||
func (j *ownJwt) Generate(signMethod jwt.SigningMethod, secret string, claims jwt.Claims) (string, error) {
|
||||
if nil == signMethod {
|
||||
signMethod = jwt.SigningMethodHS256
|
||||
}
|
||||
var (
|
||||
token *jwt.Token
|
||||
)
|
||||
|
||||
if nil == claims {
|
||||
token = jwt.New(signMethod)
|
||||
} else {
|
||||
token = jwt.NewWithClaims(signMethod, claims)
|
||||
}
|
||||
return token.SignedString([]byte(secret))
|
||||
}
|
||||
|
||||
// Validate 验证token
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:13 2023/2/11
|
||||
func (j *ownJwt) Validate(inputToken string, secret string, claims jwt.Claims) (jwt.Claims, error) {
|
||||
|
||||
var (
|
||||
token *jwt.Token
|
||||
err error
|
||||
)
|
||||
|
||||
if token, err = jwt.ParseWithClaims(inputToken, claims, func(tokenInfo *jwt.Token) (interface{}, error) {
|
||||
return []byte(secret), nil
|
||||
}); nil != err {
|
||||
return nil, errors.New("token parse fail : " + err.Error())
|
||||
}
|
||||
if !token.Valid {
|
||||
return nil, errors.New("token is valid : " + err.Error())
|
||||
}
|
||||
|
||||
return token.Claims, nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user