Skip to content
Ryan Parman edited this page Nov 3, 2024 · 2 revisions

Go (sometimes called Golang) is a fast, compiled, garbage-collected, functional programming language. It has built-in support for concurrency and asynchronous programming, and can cross-compile easily to multiple operating systems and CPU architectures.

It is a remarkably stable language, and upgrades tend to be quite uneventful (this is a good thing). It is a “batteries-included” environment with compiling, testing, fuzzing, profiling, and dependency management all built-in.

Unless there is a specific bug in the latest release that we want to avoid (quite rare), we should always plan to run the latest release.

  1. Install the Go toolchain.

    brew install go
  2. Add $GOPATH/bin to your $PATH environment variable. By default (i.e., without configuration), $GOPATH is defined as $HOME/go.

    export PATH="$PATH:$GOPATH/bin"

Version management

Generally speaking, always run the latest release. Having said that, there is occasionally a case where software needs to be updated for the latest release (usually a .0 release), and that hasn't happened yet, so we need to roll back.

Go has a built-in way of installing a specific version of Go. This approach results in a go binary with the version in the name.

go install golang.org/dl/go1.22.7@latest
go1.22.7 download
go1.22.7 version

If you are wrapping your Go calls in a Makefile, you can redefine $(GO) with:

GO=$(shell which go1.22.7)

goenv is a port from pyenv, and they work nearly identically.

  1. Install goenv.

    brew install goenv
    
  2. Add eval "$(goenv init -)" to your profile.

  3. Restart your shell.

  4. Install a specific Go version and set it to the default for this project.

    goenv install 1.22.7
    goenv rehash
    goenv local 1.22.7
    goenv version

Package management

go mod init {URL}
go get entgo.io/ent@latest
go mod tidy