You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
go-fly/tools/jwt.go

24 lines
572 B

4 years ago
package tools
import (
"github.com/dgrijalva/jwt-go"
)
const SECRET = "taoshihan"
func MakeToken(obj map[string]interface{}) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.MapClaims(obj))
tokenString, err := token.SignedString([]byte(SECRET))
return tokenString, err
}
func ParseToken(tokenStr string) map[string]interface{} {
token, err := jwt.Parse(tokenStr, func(token *jwt.Token) (i interface{}, e error) {
return []byte(SECRET), nil
})
if err != nil {
return nil
}
finToken := token.Claims.(jwt.MapClaims)
return finToken
}