An Introduction to Go Tools and Clean Code

I’ve begun learning Go and while the language has been fun to learn and use, figuring out all the tooling has been less than simple. Here’s a quick overview of a sample tool chain to get you started with community acceptable code.

Step 1: the compiler

Coming from a dynamically typed background, types and compile errors have been enjoyable (I hope the feeling lasts).

Step 2: go fmt

This tool automatically formats Go source code and as the docs explain, it:

It’s important to realize that this tool manipulates your code. You really shouldn’t commit any code without running go fmt first.

Step 3: go vet

This tool uses heuristics to catch potential issues not possible to be caught by the compiler and is the next step in clean code. This tool does not edit your code but rather prints out potential issues that should be inspected. An example issue is passing the wrong format type to a Printf statement. The docs list the possible cases handled and describe the various flags available for your use.

Step 4: golint

This tool does not edit your code either but prints out likely style violations such as returning inside an else block instead of using a guard clause (as explained in this post).

Want to learn more?