commit
384364e2f2
@ -583,7 +583,7 @@ func (p *ControllerRegister) getURL(t *Tree, url, controllerName, methodName str
|
|||||||
for _, l := range t.leaves {
|
for _, l := range t.leaves {
|
||||||
if c, ok := l.runObject.(*ControllerInfo); ok {
|
if c, ok := l.runObject.(*ControllerInfo); ok {
|
||||||
if c.routerType == routerTypeBeego &&
|
if c.routerType == routerTypeBeego &&
|
||||||
strings.HasSuffix(path.Join(c.controllerType.PkgPath(), c.controllerType.Name()), controllerName) {
|
strings.HasSuffix(path.Join(c.controllerType.PkgPath(), c.controllerType.Name()), `/`+controllerName) {
|
||||||
find := false
|
find := false
|
||||||
if HTTPMETHOD[strings.ToUpper(methodName)] {
|
if HTTPMETHOD[strings.ToUpper(methodName)] {
|
||||||
if len(c.methods) == 0 {
|
if len(c.methods) == 0 {
|
||||||
|
|||||||
@ -26,6 +26,14 @@ import (
|
|||||||
"github.com/beego/beego/v2/server/web/context"
|
"github.com/beego/beego/v2/server/web/context"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type PrefixTestController struct {
|
||||||
|
Controller
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ptc *PrefixTestController) PrefixList() {
|
||||||
|
ptc.Ctx.Output.Body([]byte("i am list in prefix test"))
|
||||||
|
}
|
||||||
|
|
||||||
type TestController struct {
|
type TestController struct {
|
||||||
Controller
|
Controller
|
||||||
}
|
}
|
||||||
@ -87,6 +95,20 @@ func (jc *JSONController) Get() {
|
|||||||
jc.Ctx.Output.Body([]byte("ok"))
|
jc.Ctx.Output.Body([]byte("ok"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrefixUrlFor(t *testing.T){
|
||||||
|
handler := NewControllerRegister()
|
||||||
|
handler.Add("/my/prefix/list", &PrefixTestController{}, "get:PrefixList")
|
||||||
|
|
||||||
|
if a := handler.URLFor(`PrefixTestController.PrefixList`); a != `/my/prefix/list` {
|
||||||
|
logs.Info(a)
|
||||||
|
t.Errorf("PrefixTestController.PrefixList must equal to /my/prefix/list")
|
||||||
|
}
|
||||||
|
if a := handler.URLFor(`TestController.PrefixList`); a != `` {
|
||||||
|
logs.Info(a)
|
||||||
|
t.Errorf("TestController.PrefixList must equal to empty string")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestUrlFor(t *testing.T) {
|
func TestUrlFor(t *testing.T) {
|
||||||
handler := NewControllerRegister()
|
handler := NewControllerRegister()
|
||||||
handler.Add("/api/list", &TestController{}, SetRouterMethods(&TestController{}, "*:List"))
|
handler.Add("/api/list", &TestController{}, SetRouterMethods(&TestController{}, "*:List"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user