mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix issue in router group registering for controller
This commit is contained in:
@ -293,9 +293,17 @@ func (g *RouterGroup) doBind(bindType string, pattern string, object interface{}
|
||||
} else if g.isController(object) {
|
||||
if len(extras) > 0 {
|
||||
if g.server != nil {
|
||||
g.server.doBindControllerMethod(pattern, object.(Controller), extras[0], g.middleware)
|
||||
if gstr.Contains(extras[0], ",") {
|
||||
g.server.doBindController(pattern, object.(Controller), extras[0], g.middleware)
|
||||
} else {
|
||||
g.server.doBindControllerMethod(pattern, object.(Controller), extras[0], g.middleware)
|
||||
}
|
||||
} else {
|
||||
g.domain.doBindControllerMethod(pattern, object.(Controller), extras[0], g.middleware)
|
||||
if gstr.Contains(extras[0], ",") {
|
||||
g.domain.doBindController(pattern, object.(Controller), extras[0], g.middleware)
|
||||
} else {
|
||||
g.domain.doBindControllerMethod(pattern, object.(Controller), extras[0], g.middleware)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if g.server != nil {
|
||||
|
||||
@ -4,7 +4,6 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://github.com/gogf/gf.
|
||||
|
||||
// 分组路由测试
|
||||
package ghttp_test
|
||||
|
||||
import (
|
||||
@ -118,7 +117,7 @@ func Test_Router_GroupBasic1(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Router_Basic2(t *testing.T) {
|
||||
func Test_Router_GroupBasic2(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
obj := new(GroupObject)
|
||||
@ -191,3 +190,27 @@ func Test_Router_GroupBuildInVar(t *testing.T) {
|
||||
gtest.Assert(client.DeleteContent("/api/ThisDoesNotExist"), "Not Found")
|
||||
})
|
||||
}
|
||||
|
||||
func Test_Router_Group_Mthods(t *testing.T) {
|
||||
p := ports.PopRand()
|
||||
s := g.Server(p)
|
||||
obj := new(GroupObject)
|
||||
ctl := new(GroupController)
|
||||
group := s.Group("/")
|
||||
group.ALL("/obj", obj, "Show, Delete")
|
||||
group.ALL("/ctl", ctl, "Show, Post")
|
||||
s.SetPort(p)
|
||||
s.SetDumpRouterMap(false)
|
||||
s.Start()
|
||||
defer s.Shutdown()
|
||||
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
gtest.Case(t, func() {
|
||||
client := ghttp.NewClient()
|
||||
client.SetPrefix(fmt.Sprintf("http://127.0.0.1:%d", p))
|
||||
gtest.Assert(client.GetContent("/ctl/show"), "1Controller Show2")
|
||||
gtest.Assert(client.GetContent("/ctl/post"), "1Controller Post2")
|
||||
gtest.Assert(client.GetContent("/obj/show"), "1Object Show2")
|
||||
gtest.Assert(client.GetContent("/obj/delete"), "1Object Delete2")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user