5 Tips To Speed Up Golang Development With IntelliJ Or Goland

Keith Perry
May 2, 2019 · 4 min read

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

err live template, type “err” and then hit 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!

Keith Perry

Written by

I am a software engineer by trade, and this is my latest take on software and technology. Disclaimer: Of my opinion only (not my employers).

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade