feat: 目录及代码优化调整

This commit is contained in:
meilin.huang
2021-03-24 17:18:39 +08:00
parent 4c2e6b6155
commit 39e9f15def
116 changed files with 2964 additions and 310 deletions

View File

@@ -0,0 +1,29 @@
package ctx
import (
"mayfly-go/base/biz"
)
func init() {
BeforeHandlers = append(BeforeHandlers, new(PermissionHandler))
}
var permissionError = biz.NewBizErrCode(501, "token error")
type PermissionHandler struct{}
func (p *PermissionHandler) Handler(rc *ReqCtx) error {
if !rc.NeedToken {
return nil
}
tokenStr := rc.Req.Header.Get("Authorization")
if tokenStr == "" {
return permissionError
}
loginAccount, err := ParseToken(tokenStr)
if err != nil || loginAccount == nil {
return permissionError
}
rc.LoginAccount = loginAccount
return nil
}