-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
目前go-zero自带的jwt校验失败后,返回的响应体是空的,我翻遍了官方文档,没看到定制响应体内容的方法,又看了一下源码,发现是可以调用callback的:
Line 70 in 271f105
func (ng *engine) appendAuthHandler(fr featuredRoutes, chn chain.Chain, |
func (ng *engine) appendAuthHandler(fr featuredRoutes, chn chain.Chain,
verifier func(chain.Chain) chain.Chain) chain.Chain {
if fr.jwt.enabled {
if len(fr.jwt.prevSecret) == 0 {
chn = chn.Append(handler.Authorize(fr.jwt.secret,
handler.WithUnauthorizedCallback(ng.unauthorizedCallback)))
} else {
chn = chn.Append(handler.Authorize(fr.jwt.secret,
handler.WithPrevSecret(fr.jwt.prevSecret),
handler.WithUnauthorizedCallback(ng.unauthorizedCallback)))
}
}
return verifier(chn)
Line 313 in 271f105
// WithUnauthorizedCallback returns a RunOption that with given unauthorized callback set. |
// WithUnauthorizedCallback returns a RunOption that with given unauthorized callback set.
func WithUnauthorizedCallback(callback handler.UnauthorizedCallback) RunOption {
return func(svr *Server) {
svr.ngin.setUnauthorizedCallback(callback)
}
}
但是配置UnauthorizedCallback的位置应该是在生成的routes.go文件里,这个文件应该不能修改。
所以,我想问问,怎么做才能生成定制的响应体?
Metadata
Metadata
Assignees
Labels
No labels