Skip to content

Instantly share code, notes, and snippets.

@bobisme
Created April 7, 2017 19:46
Show Gist options
  • Save bobisme/9fbad385cf5d9568c3662cb5d0d3b822 to your computer and use it in GitHub Desktop.
Save bobisme/9fbad385cf5d9568c3662cb5d0d3b822 to your computer and use it in GitHub Desktop.

There are 3 tools/tricks which are pretty essential to writing Go code on a team or open source project which I highly recommend:

  1. Set up your editor to automatically run the code through goimports once you hit save.

    It's extremely fast. It formats your code using the standard gofmt tool. It automatically adds/removes/organizes your import lines. Note that Go uses tabs, so I recommend setting your editor's tab-width to 2 or 4, whichever you're used to. Anything but 8. Editor support:

  2. Run your code through go vet it will catch some unexpected things that the compiler might miss.

    Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string. Vet uses heuristics that do not guarantee all reports are genuine problems, but it can find errors not caught by the compilers.

  3. Run your code through golint to round-out your style. It generally beats people up about naming and comments.

Rock on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment