remove jwt

This commit is contained in:
白茶清欢 2023-08-10 17:32:31 +08:00
parent 024a0e5e96
commit ddd2413386
2 changed files with 0 additions and 69 deletions

View File

@ -24,8 +24,6 @@ var (
Project *project Project *project
// Array 数组操作 // Array 数组操作
Array *array Array *array
// JWT ...
JWT *ownJwt
// Console 控制台输出数据 // Console 控制台输出数据
Console *console Console *console
// PinYin 汉字转拼音 // PinYin 汉字转拼音
@ -41,7 +39,6 @@ func init() {
Calculate = &calculate{} Calculate = &calculate{}
Project = &project{} Project = &project{}
Array = &array{} Array = &array{}
JWT = &ownJwt{}
Console = &console{} Console = &console{}
PinYin = &pinYin{} PinYin = &pinYin{}
} }

66
jwt.go
View File

@ -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
}