I am just starting up in Go and decided to make a simple project to implement some popular sorting algorithms to see how well I understand the language basics. Turns out I don't understand them very well and I need a debugger! So naturally I turn to JetBrains and download their newest Gogland.
The problem I have now run into is that it refuses to acknowledge that I have a package of files and won't let me build/run my program in the debugger or at all. Are there any IDEs you would reccommend that is in a more stable place? Or perhaps you know why Gogland is having this issue?
评论:
feddasch:
whizack:Are there any IDEs you would reccommend that is in a more stable place?
Visual Studio Code +
lukehoban.Go
extension (Marketplace)
Zy14rk:Agreed, I've used intellij, gogland, and atom for quite some time, but vscode has worked best for me so far.
fridolinKarlAdalin:Second this. VS Code is great with Go. Integrates very well with the go toolset as well. All one need do is install the Go extension by lukehoban - and the rest you'll get promted to install afterwards. Up and running in less than ten hassle free minutes :)
kataclysm1337:What exactly ist the Problem with GogLand? Is there an error message? Have you set the go path for the project?
fridolinKarlAdalin:I believe I have set the path, but maybe I am not doing that properly. The error I get is when I try to create a run configuration for Go Application. I then change the Run Kind to Paackage. I set the Working directory to my GoglandProjects/Project folder, made an Environment variable for GOPATH that goes to this directory, set Module to my Project, and have attempted to give this project folder path as the Package path. Gogland then gives me the error near the bottom "Cannot find package /home/homedir/GoglandProjects/Project"
kataclysm1337:The problem seems to be that your GOPATH has the wrong directory structure. You should check out this GOPATH documentation. In short, inside your GOPATH you need three subdirectories: src, bin and pkg. Your source code belongs in src. Inside here you should create a directory for your source control, for example github.com. In this folder create a new foder with you username. And last but not least a new directory for your package. In the end your structure should look like this example: GOPATH/src/github.com/kataclysm1337/my-package. The path after src describes your import path for the package, so you would import it with import "github.com/kataclysm1337/my-package". I believe the problem is, that GogLand cannot find a src folder inside your GOPATH.
kataclysm1337:I have added this src folder and added my files to it. I am still getting the same error message though.
fridolinKarlAdalin:nevermind I think I finally got it!
kataclysm1337:What was the problem?
PacNinja:What you said was the problem I had accidentally miss spelled something while trying to use your solution.
Ping /u/dlsniper for Gogland issues.
Are there any IDEs you would reccommend that is in a more stable place?
Try VS Code with vs-go plugin. They also have debugging support in the works.
Links:
- https://code.visualstudio.com/
- https://github.com/Microsoft/vscode-go
- https://github.com/Microsoft/vscode-go/wiki/Debugging-Go-code-using-VS-Code
kataclysm1337:Atom with the go-plus package, which is actually a collection of packages that turn Atom into a powerful Go IDE.
joncalhoun:Would this include a debugger?
sondeckis:go-debug is the most common debugger in atom and uses delve behind the scenes to power the UI.
dlsniper:I want to add a question: I can not make it work without adding project gopath. https://pasteboard.co/8T6J1pan2.png Setting this folder is mandatory? If yes then why it is not set by default (when creating new project)
dlsniper:You need to follow the Go Workspace layout for your GOPATH https://golang.org/doc/code.html#Workspaces Go projects need to be in such a Go Workspace (or GOPATH) in order for them to work, there's just no way around it.
What you are showing in the picture seems to be a correct Go Workspace. In this case you can let the IDE create the project in C:\WorkPersonal\chat\src\github.com\sondeckins\chat and set the GOPATH to C:\WorkPersonal\chat (as you have in the picture). This will allow you to have a nicer view of the project. Hope it helps.
Normally the GOPATH is set only once, in the environment, the IDE can infer that automatically for all projects, but in your case the GOPATH doesn't seem to be in the environment thus the IDE can't pick it up automatically.
I've seen the issue and that it has been sorted out and notified the developers as well about this. Thanks for the ping /u/PacNinja.
