Setting up to Go
Install
Install Go lang from go.dev.
To update, download and install the new version.
To uninstall, rm -rf /usr/local/go
.
Hello, world!
Create a hello.go
file.
1
2
3
4
5
6
7
|
package main
import "fmt"
func main() {
fmt.Printf("Hello, world!\n")
}
|
go run hello.go
Build a native binary in release mode.
1
|
go build -tags release hello.go
|
To cross compile
1
2
3
4
5
6
7
8
9
10
11
|
# List all available targets (GOOS/GOARCH pairs)
go tool dist list
# Build a binary for Windows on 64 bit x86
GOOS=windows GOARCH=amd64 go build -tags release hello.go
# For Linux on 64 bit x86
GOOS=linux GOARCH=amd64 go build -tags release hello.go
# For Linux on ARM 64 bit
GOOS=linux GOARCH=arm64 go build -tags release hello.go
|