Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var JWT = func(ctx *context.Context) { var code int var data interface{} code = e.SUCCESS Authorization := ctx.Input.Header("Authorization") fmt.Println(Authorization) token := strings.Split(Authorization, " ") fmt.Println(token) if Authorization == "" { code = e.NO_AUTH fmt.Println(Authorization) } else { fmt.Println("token", token[1]) _, err := ParseToken(token[1]) if err != nil { switch err.(*jwt.ValidationError).Errors { case jwt.ValidationErrorExpired: code = e.ERROR_AUTH_CHECK_TOKEN_TIMEOUT default: code = e.ERROR_AUTH_CHECK_TOKEN_FAIL } } } if code != e.SUCCESS { ResponseWithJson(ctx.ResponseWriter, http.StatusBadRequest, Response{Code: code, Msg: e.GetMsg(code), Data: data}) return } }
验证token拦截器
View Source
var JwtSecret = []byte("jcops")
Functions ¶
func GetIdFromClaims ¶
func ResponseWithJson ¶
func ResponseWithJson(w http.ResponseWriter, code int, payload interface{})
Types ¶
Click to show internal directories.
Click to hide internal directories.