Beego: Use go mod the router namespace does not work?

Created on 19 Dec 2018  ·  4Comments  ·  Source: astaxie/beego

  1. use bee api myproject to new a project,
  2. then copy it out of the GOPATH
  3. go mod init myproject
  4. go build

Use the four steps above, then run it, all router is 404, look at the http://localhost:8088/listconf?command=router , routers is empty

I just started learning golang

thanks

Most helpful comment

我发现了一些东西
在 beego.NSInclude 调用了 ns.Include,然后调用了 n.handlers.Include,在这个Include里面做了一些操作,到 GOPATH 中去找include的对应的文件,解析该文件生成路由,监听文件改动

所以在找controller文件的时候找不到,自然路由就没有注册成功,所以目前用了 go module 就不能用 NSInclude,但是 NSRouter 还是可以用的


I found something
In beego.NSInclude call ns.Include, then call n.handlers.Include, do some operations in this Include, go to GOPATH to find the corresponding file of include, parse the file, generate routing, listen for file changes

So when I find the controller file, I can't find it. The natural route is not registered successfully. So I can't use NSInclude with go module, but NSRouter can still work fine.

All 4 comments

i meet this problum too,import ( "controllers" "github.com/astaxie/beego" ) it dosent work

For me, the problem was in not importing context from github.com/astaxie/beego/context. The tool I was using imported it from my project (which surprised me, as I didn't think it had a package with that name).

我发现了一些东西
在 beego.NSInclude 调用了 ns.Include,然后调用了 n.handlers.Include,在这个Include里面做了一些操作,到 GOPATH 中去找include的对应的文件,解析该文件生成路由,监听文件改动

所以在找controller文件的时候找不到,自然路由就没有注册成功,所以目前用了 go module 就不能用 NSInclude,但是 NSRouter 还是可以用的


I found something
In beego.NSInclude call ns.Include, then call n.handlers.Include, do some operations in this Include, go to GOPATH to find the corresponding file of include, parse the file, generate routing, listen for file changes

So when I find the controller file, I can't find it. The natural route is not registered successfully. So I can't use NSInclude with go module, but NSRouter can still work fine.

目前也是用 ns.Router

Was this page helpful?
0 / 5 - 0 ratings