$ mkdir -p $HOME/go/src/github.com/user

$ vi ~/.bash_profile
export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin

$ brew install go

$ HOME/go/src/github.com/user

$ mkdir hello

$ cd hello

$ go mod init github.com/user/hello

$ vi hello.go
package main

import "fmt"

func main() {
	fmt.Println("Hello, world.")
}

$ go run hello.go

macos - Install go with brew, and running the gotour - Stack Overflow

How to Write Go Code - The Go Programming Language