英文:
How to run/debug a beego app using Gogland (go language)
问题
我正在使用Gogland(JetBrains的IDE,版本为1.0 Preview/EAP Feb, 10 2017)来创建一个Beego web应用程序。
我可以通过命令行运行它:
bee run
一切正常。
当我访问localhost:8080时,它显示无法找到路径中的模板文件:
我以为这与GOPATH有关,但后来我意识到Gogland IDE可能是在运行
go run main.go
而不是
bee go
当我在shell中运行
go run main.go
时,我遇到了相同的问题:找不到模板。
我甚至尝试从IDE运行'bee'命令。我部分成功了。使用这个配置:
我可以从IDE运行它,但调试器不会在任何断点处停止。也就是说,我只能从Gogland运行(但不能调试)它。
所以我的问题是如何使Gogland IDE调试一个beego项目
英文:
Im using Gogland (IDE from JetBrains. Version 1.0 Preview/EAP Feb, 10 2017) to create a Beego web app.
I can run it from command line with:
> bee run
and everything works.
However if I run it from the IDE with the following configuration
when I go to localhost:8080 it says it can not find the template file in path:
I thought it was related to GOPATH, but then I realized that Gogland IDE is probably running
> go run main.go
instead of
> bee go
and when I checked runing
> go run main.go
from the shell, I got the same issue: cant find the template.
I even tried to run the 'bee' command from the IDE. I partially succeed. With this configuration:
I can run it from the IDE, but the debugger doesn't stop in any breakpoint. IE: I can only run (but not debug) it, from Gogland.
So my question is how to make gogland IDE debug a beego project
答案1
得分: 1
使用Delve和远程调试配置(从gogland eap9开始)。
像这样运行你的bee应用程序:
bee dlv -package="app_name" -port=2345
在gogland中,使用之前设置的端口配置Go Remote。
英文:
Use Delve and Remote Debugging Configuration(start from gogland eap9).
Run your bee app like:
bee dlv -package="app_name" -port=2345
On gogland make configuration Go Remote with port which you set previous.
答案2
得分: 0
你无法更改IDE来运行bee命令。但是,你可以通过转到运行 | 编辑配置 | + | Go应用程序来更改运行配置为Go应用程序,然后选择包类型,然后输入完整的包名称(例如,如果你的主包在GOPATH/src/github.com/dlsniper/demo下,则输入github.com/dlsniper/demo
),并确保工作目录设置正确。希望对你有帮助。
英文:
You cannot change the IDE to run the bee command. However, you can change the run configuration to a Go Application by going to Run | Edit Configurations | + | Go Application select the package type then type the full package name (github.com/dlsniper/demo
for example if your package main is under GOPATH/src/github.com/dlsniper/demo) and make sure the working directory is where you need it to be. Hope it helps.
答案3
得分: 0
我通过设置以下内容来解决这个问题:
beego.BConfig.WebConfig.ViewsPath = "/Users/xxxxx/go/src/xxxxxxx/views" // 你的视图目录
另外,如果你有静态路径,你也应该使用绝对路径。例如:beego.SetStaticPath("/static", "/Users/xxx/go/src/xxxx/static")
这只在调试时使用,如果你发布程序,应该移除这个硬编码的配置。
英文:
I resolve this by setting:
beego.BConfig.WebConfig.ViewsPath="/Users/xxxxx/go/src/xxxxxxx/views" // your views directory
by the way: if you have staticpath , you should also use absolute path.
eg: beego.SetStaticPath("/static", "/Users/xxx/go/src/xxxx/static")
it's only used when debug, if you publish your program, you should remove this hard code config.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论