Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

NCUHOME/PJWTC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

17 Commits

Repository files navigation

PJWTC

passport jwt 解析 Gin 中间件

使用中间件

默认值使用集群内连接地址,如需覆盖,可以设置环境变量 PJWT_ADDR

package middlewares
import (
 "github.com/gin-gonic/gin"
 pjwt "github.com/ncuhome/PJWTC"
 "log"
)
func Auth() gin.HandlerFunc {
	middleware, err := pjwt.New(pjwt.Handlers{
		ParseError: func(c *gin.Context, err error) {
			c.AbortWithStatus(401)
		},
		ServerError: func(c *gin.Context, err error) {
			c.AbortWithStatus(500)
		},
		Success: func(c *gin.Context, xh string) {
			c.Set("xh", xh)
		},
	})
	if err != nil {
		log.Fatalln("初始化鉴权中间件失败:", err)
	}
	
	return middleware.Handler()
}

About

passport jwt 第三方解析服务 中间件

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /