diff --git a/ChangeLog.md b/ChangeLog.md index 300ec3e..04d814b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,8 @@ Change Log 更新说明 ------------------------------ +## 2022-01-29 v1.4.5.1 +1. 支持登录,登出仅注册Post,Get等方式 + ## 2021-08-25 v1.4.5 1. 优化框架日志,常量; 2. 启动加入error错误返回,避免异常继续执行; diff --git a/gtoken/gtoken_group.go b/gtoken/gtoken_group.go index c2dac35..05d3a24 100644 --- a/gtoken/gtoken_group.go +++ b/gtoken/gtoken_group.go @@ -4,6 +4,7 @@ import ( "errors" "github.com/gogf/gf/frame/g" "github.com/gogf/gf/net/ghttp" + "github.com/gogf/gf/text/gstr" ) // Middleware 绑定group @@ -33,8 +34,20 @@ func (m *GfToken) Middleware(group *ghttp.RouterGroup) error { } group.Middleware(m.authMiddleware) - group.ALL(m.LoginPath, m.Login) - group.ALL(m.LogoutPath, m.Logout) + + registerFunc(group, m.LoginPath, m.Login) + registerFunc(group, m.LogoutPath, m.Logout) return nil } + +// 如果包含请求方式,按照请求方式注册;默认注册所有 +func registerFunc(group *ghttp.RouterGroup, pattern string, object interface{}) { + if gstr.Contains(pattern, ":") || gstr.Contains(pattern, "@") { + group.Map(map[string]interface{}{ + pattern: object, + }) + } else { + group.ALL(pattern, object) + } +}