Cleaning up, building, and running tests on save

Since the Go core team has provided us with such great tools as fmt, vet, test, and goimports, we are going to look at a development practice that has proven to be extremely useful. Whenever we save a .go file, we want to perform the following tasks automatically:

  1. Use goimports and fmt to fix our imports and format the code.
  2. Vet the code for any faux pas and tell us immediately.
  3. Attempt to build the current package and output any build errors.
  4. If the build is successful, run the tests for the package and output any failures.

Because Go code compiles so quickly (Rob Pike once actually said that it doesn't build quickly, but it's just not slow like everything else), we can comfortably build entire packages ...

Get Go Programming Blueprints - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.