package jwt import ( jwt_lib "github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go/request" "github.com/gin-gonic/gin" ) func Auth(secret string) gin.HandlerFunc { return func(c *gin.Context) { _, err := request.ParseFromRequest(c.Request, request.OAuth2Extractor, func(token *jwt_lib.Token) (interface{}, error) { b := ([]byte(secret)) return b, nil }) if err != nil { c.AbortWithError(401, err) } } }