5 Tips To Speed Up Golang Development With IntelliJ Or Goland

While I mentioned in a previous post that I started learning golang, it has been almost a year since I started learning. I have also posted about basic performance testing using golang, but this time, I thought it might be nice to post about some IDE tips. If you want some simple tips to help speed up development, then keep on reading.

1. Implement Interface

Implement Interface is a hidden gem that can be found by using the common Intellij keystroke combo ⌥ (Option/Alt) + Enter on the struct that you wish to implement the interface. This will open a search window, and you can type the interface that you wish to implement.

2. Extract Interface

I wish this had a great keyboard combination, but it doesn’t currently by default. If you wish to extract an interface, then you need to Right-Click on struct → RefactorExtractInterface. Once the menu pops up it asks you more information, name, file to add to, package…etc. I still use this quite often.

3. Live Templates

Live templates are awesome for quickly generating some code that you commonly use. In general, you type in a few characters and then hit tab. Some built in live templates are forr which generates a for range loop (you need the extra “r”) and err which allow you to handle errors quickly. These are really powerful because you can also create your own live templates. For example, if you have a common logging framework when you logged “info” you could create logi as your own template which would generate your “log.info” statement. If you have a hard time remembering these, just remember one keyboard combo: (Command) + j — this will show you all available templates within the context of the block of code where your cursor is at. Enjoy these examples below:

3a. forr — for range loop

To execute this live template, just type “forr” + tab

3b. err — check for error and handle

To execute this live template, just type “err” + tab

4. Fill Struct

I am not exactly sure when this was released, but it is glorious. If are familiar constructors in Java or C#, then you were used to a little IDE help when you instantiated a new class. This gives you that same power (albeit a little more clunky). In this case, if you have a struct that you are creating, then if you put your cursor between the brackets {}, then hit ⌥ (Option/Alt) + Enter, it will give you the option of “Fill Struct” or “Fill Struct Recursively”. Choose one. Save your typing for some other fun code, and let this thing do its work!

5. Generate test cases/test file

This is probably my favorite. I am pretty passionate about writing testable code and unit testing in general. I really think that writing testable code using SOLID principles will help you design better and more maintainable code. I found this nugget pretty early in my golang learnings, but it is definitely my most used feature. If you put your cursor on a method, type ⌃(Control) + n , and this will bring up the “Generate” menu, and from here you can select “Test for function” or “Test for file” and if the _test.go file doesn’t exist, it will create it for you along with the outline of parameterized/table tests for your functions. Pretty awesome.

What did I miss?

Do you have some awesome tips that you would like to share that I missed? Please discuss in the comments or on hacker news.

Thanks for reading!

Thankful Dad, Husband, and Principal Software Engineer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store