Lecstor's Blog

Golang Cheatsheet

January 27, 2019

Learning Go, so started recording references to all the useful things I find so I can find them again when I need them..

Install

$ brew update && brew install go

or download from Golang Downloads and install

Testing

$ go test - run tests

Generate Tests

gotests - Generate Go tests from your source code

$ gotests -w -all ./client.go > client_test.go

Coverage

$ go test -cover - run tests and write coverage profile to cover.out

$ go tool cover -html=cover.out - view covered/not covered code in browser

go tool cover -help - for more

Testing Resources

Trouble-shooting

Cache Clean

Cleaning the go caches once fixed some “unknown import path”/“cannot find module providing package” errors (Package Clean)

$ go clean -cache -modcache -i -r

Resources


Jason Galea

Written by Jason Galea from Cairns, Australia.

I work at SafetyCulture on the SafetyCulture web app, with React & Node, backing the awsome iAuditor mobile app for iOS and Android.

Twitter | Github