Assorted Go tutes!
- First, install:
brew search go
brew info go
brew install go
brew upgrade go
which go
go version
- Optionally, set:
export GOPATH="${HOME}/go"
export GOROOT="$(brew --prefix golang)/libexec"
export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"
go get golang.org/x/lint/golint
which golint
golint -h
- Second, read:
go help
go help gopath
go help packages
go help modules
- Third, get-started:
go env
go env GOROOT
go env GOPATH
- Simple World
mkdir simple
cd simple
vi main.go
go build .
./simple
go build -o simple.exe
./simple.exe
[source.go, code.go] < package < module < repository
mkdir hello
cd hello
go mod init github.com/victorskl/go-tute/hello
vi hello.go
go install github.com/victorskl/go-tute/hello
go install .
go install
tree $GOPATH/bin
which hello
hello
mkdir morestrings
cd morestrings
vi morestrings
go build
cd ..
go install
hello
go get github.com/google/go-cmp/cmp
vi hello.go
go install
hello
go help go.mod
cd morestrings
vi reverse_test.go
go test
go help test
- Go Module
go.mod
take care of dependencies. - Go codes are organised in packages which then arranged in a module.
- A Go module is published in a repository.
- A repository can contain multi-modules. 🙋♂️ This
go-tute
is a multi-modules Go repo, for example! - Go executable entrypoint bears a package name "main" and
func main()
. - Go build use parent directory name as an executable name, if
-o
flag is absent. - Go standard community proposes some project structure and naming convention. This structure is known to be a traditional monolith structure.
- You can, however, arrange your Go project whichever way you like!
- Though,
go.mod
favours fan-out multiple repositories; with each repository contain only one Go module; andgo.mod
take care of inter-dependencies between these Go modules.