Compiling Go files

直接运行

go run x.go

编译适配本机并移除路径信息、符号表、调试信息的版本

go build -trimpath -ldflags "-s -w" x.go

在Windows上交叉编译

指定系统为linux

$env:GOOS = "linux"

指定架构为amd64

$env:GOARCH = "amd64"

在Linux/MacOS上交叉编译

编译系统为linux,架构为amd64,并移除路径信息、符号表、调试信息的版本

GOOS=linux GOARCH=amd64 go build -trimpath -ldflags "-s -w" x.go

模块

在当前目录中初始化模块

go mod init x

下载依赖包

go get github.com/x

整理依赖

go mod tidy