Golang setup

Go made some changes in v1.16 to how go get does things and moved some of that over to go install. Most of the guides I was looking at to learn some things referenced the old way of accomplishing stuff. These notes are what worked for me when using go 1.17.

$PATH

$GOBIN defines where the created executables end up, by default it’s $GOPATH/bin. I’ve set this to ~/.local/bin since I like to keep my PATH clutter-free and would prefer not to put $GOPATH/bin in there.

echo "export GOPATH=\${HOME}/go" >> ~/.zshrc
echo "export GOBIN=\${GOPATH}/bin" >> ~/.zshrc
echo "export PATH=${PATH}:${GOBIN}

The things that vscode wants

I noticed that the VScode Go extension installs some utilities the now-deprecated way (go get) which I am just choosing to install myself for now, the new way (go install)

go install golang.org/x/tools/gopls@latest
go install github.com/ramya-rao-a/go-outline@latest
go install github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install github.com/go-delve/delve/cmd/dlv@latest
go install github.com/cweill/gotests/gotests@latest
go install github.com/fatih/gomodifytags@latest
go install github.com/josharian/impl@latest
go install github.com/haya14busa/goplay/cmd/goplay@latest

Cobra

Cobra is a utility for making great CLI programs. A couple examples of projects that use this are kubernetes kubectl and docker. One of the really cool features of cobra is that you get shell completion for free, eg: source <(myctl completion bash). This requires zero extra configuration or code. It just works.

go install github.com/spf13/cobra/cobra@latest

Setup a project using Cobra

mkdir -p ~/go/src/project
cd ~/go/src/project
cobra init --pkg-name gitlab.pwned.com/cstevens/project
go mod init gitlab.pwned.com/cstevens/project
go mod tidy