如何使用Gogland(go语言)运行/调试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 enter image description here

when I go to localhost:8080 it says it can not find the template file in path:

enter image description here

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: enter image description hereI 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

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.

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.

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.