In this post, I’m going to explain how I set up my development environment mainly for developing Golang applications. I’ll be using VS Code but I’m sure you can use the same tooling if you are developing in GoLand.

Also I’ll be skipping the obvious parts such as how to install VS Code or the Go compiler itself.

First things first, we need a good linter

I highly recommend using golangci-lint. It’s very vast, and combines multiple lint tools including staticcheck which is one of my favorite tools and is enabled by default.

Enabling it on VS Code is just as easy as going to the settings and selecting golangci-lint for your Go lint tool. Or you can edit the settings.json file (type “open settings (JSON)” in the command palette) and adding the following line:

{
    "go.lintTool": "golangci-lint"
}

After selecting it, the editor will ask you to install a few dependencies (if you don’t have them already).

Second, let’s break the long lines

I work in different environments. At home I do have a wide monitor but while coding on the go (No pun intended 😆), I’m left with my laptop’s monitor which is not ideal for reading long lines. To fix this problem, I’ve found this handy formatter called golines which shortens the long lines.

Basically it changes this:

myMap := map[string]string{"first key": "first value", "second key": "second value", "third key": "third value", "fourth key": "fourth value", "fifth key": "fifth value"}

To this:

myMap := map[string]string{
	"first key": "first value",
	"second key": "second value",
	"third key": "third value",
	"fourth key": "fourth value",
	"fifth key": "fifth value",
}

In my opinion, it looks much more readable no matter how wide your display is.

In order to install it, you need to first install the executable by running:

go install github.com/segmentio/golines@latest

Then install Run On Save extension for VS code, which allows you to run a command when a file is saved.

Now open settings.json file (type “Open settings (JSON)” in the command palette) and add the following config:

{
    "emeraldwalk.runonsave": {
        "commands": [
            {
                "match": "\\.go$",
                "cmd": "golines ${file} -w"
            }
        ]
    }
}

The default behavior, shortens the lines that are longer than 100 columns. If you want to change this number you can use the -m flag, for example: "cmd": "golines ${file} -w -m 80". I’m pretty happy with the default configuration.

Finally, a list of extensions that I find useful (in no particular order)