He that will do his work well must first sharpen his tools. The same is true for development engineers, and the right development tool can greatly improve our development efficiency and ability to locate problems.
Golang IDE is not widely accepted by Gopher. Goland and VSCode are probably the most popular. Vim-go is really not recommended, the entry curve is too steep, too flashy (vim party don’t criticize me), we just write programs, why bother yourself.
Goland and Vscode are used together in my daily development. The only thing I find inconvenient about VsCode is the Debug function of VsCode, which is difficult to configure and always feels very stuck.
In this article, I’ll introduce you to some of the most common techniques used in Goland development to help you get started quickly.
Goland Debug debugging
First of all, delve is too weak for someone who is used to GDB.
For example, GDB has a very powerful x[1] feature to observe variable memory distribution. Delve didn’t offer this feature until version 1.7.0. I tried it briefly and it didn’t work as expected, but it worked. I won’t go into details here. If you are interested, delve Help X can check it out.
Most of the time I like to use Goland to debug the code and basically meet the daily development needs. Here are some ways to enter Debug mode.
For back-end development, a handy interface debugging tool is indispensable. Before introducing how to debug an interface, you are advised to use several interface debugging tools.
-
REST Postman[2]
-
GRPC Bloomrpc[3]
-
GraphQL Insomnia[4]
How to debug the interface is not described in text here, the specific steps provided in the GIF.
Main steps:
-
Breaking point
-
Click the Debug button to start the program
-
Postman calls the interface
-
Step through
In some cases, the interface calls to the underlying function keep reporting errors after we wrap it. It would be very troublesome to use the debug from outside layer by layer, and it is also very convenient to use the single test function as the debug entry.
Set the parameters
In general, whether we use Goland to start the program or Debug, we will encounter situations where parameters are entered. This is an important feature, but many students can’t set it.
Main steps:
-
Click on the upper right: Edit Configuration…
-
In the dialog box that is displayed, select the correct Working Directory
-
Fill in the corresponding parameters in Program Arguments
Go tool chain introduced
Those of you who use Vscode will notice that when we open the Go source file, we are prompted to install a complete toolchain, and Vscode is far superior to Goland in this regard. Goland not only does not have the function of one-click import, and every project needs to be introduced again, which is really too pit.
Goland can introduce Gofmt, GoImport, and of course customize other related tools. But in my case, gofMT is fine.
Recommend some useful plug-ins
-
ideaVim
-
Material Theme UI
-
Monokai Pro theme
Goland inexplicable Index failure
Goland may encounter unexplained Index failures while in use. You can recreate the Index by following these steps.
-
go mod tidy
-
go build .
-
Goland -> Preferences -> Go Modules -> Enable Go Modules Integration -> Configure GoProxy
-
Right-click the project root Directory ->Mark Directory as -> Resource root
-
Restart the Goland
If your program builds normally after the above steps, but Goland still displays “Unresolved reference “, you’ve won the lottery.
Goland has a very low probability that Index will completely fail and cannot be recovered. This is a Goland Bug, and the probability is not very high.
Solution:
There is no solution. This is what I usually do: delete Goland completely and reinstall it.
Are you interested in the Goland tips in this article? Feel free to leave a comment and I will continue to post future chapters (including vscode) if the response is good.
[1] x: visualgdb.com/gdbreferenc…
[2] Postman: www.postman.com/
[3] Bloomrpc: github.com/uw-labs/blo…
[4] Insomnia: support.insomnia.rest/=