工具 & 效率8 分钟阅读
Go 开发命令 100 条
本文整理现代 Go Modules 项目常用的 100 条命令,覆盖环境、模块、依赖、构建、测试、覆盖率、性能、诊断和发布。示例按当前 Go 工具链编写;涉及 toolchain、遥测、漏洞扫描等能力时,应确认本机版本和企业策略。
2026年8月19日阅读—点赞—收藏—
dba100go墨力计划
在知识库中专注阅读,并随时返回相关工具与课程
本文整理现代 Go Modules 项目常用的 100 条命令,覆盖环境、模块、依赖、构建、测试、覆盖率、性能、诊断和发布。示例按当前 Go 工具链编写;涉及 toolchain、遥测、漏洞扫描等能力时,应确认本机版本和企业策略。
本文整理现代 Go Modules 项目常用的 100 条命令,覆盖环境、模块、依赖、构建、测试、覆盖率、性能、诊断和发布。示例按当前 Go 工具链编写;涉及 toolchain、遥测、漏洞扫描等能力时,应确认本机版本和企业策略。
1go version1go env1go env GOROOT GOPATH GOMOD GOPROXY1go env -json1go tool dist list1go help1go help build1go help packages1go tool1go telemetry1go mod init example.com/acme/app1go env GOMOD1go mod tidy1go mod verify1go mod download1go mod download -json all1go mod graph1go mod why -m golang.org/x/text1go mod edit -go=1.251go mod vendor1go get github.com/google/uuid@latest1go get github.com/google/uuid@v1.6.01go get -u ./...1go list -m -u all1go list -m all1go list -m -versions github.com/google/uuid1go mod edit -replace example.com/lib=../lib1go mod edit -dropreplace example.com/lib1go install golang.org/x/tools/cmd/goimports@latest1govulncheck ./...1go run .1go run main.go1go run . --config config.yaml1go build .1go build -o bin/app ./cmd/app1go build -x ./...1go build -n ./...1go clean -cache1go clean -testcache1go install ./cmd/app1GOOS=linux GOARCH=amd64 go build -o bin/app-linux-amd64 ./cmd/app1GOOS=linux GOARCH=arm64 go build -o bin/app-linux-arm64 ./cmd/app1GOOS=windows GOARCH=amd64 go build -o bin/app.exe ./cmd/app1CGO_ENABLED=0 go build -o bin/app ./cmd/app1go build -trimpath -ldflags='-s -w' -o bin/app ./cmd/app1go build -ldflags="-X main.version=v1.2.3" -o bin/app ./cmd/app1go version -m bin/app1go tool buildid bin/app1go tool nm bin/app | head1go tool nm -size -sort size bin/app | tail1go fmt ./...1gofmt -w main.go1gofmt -l .1goimports -w .1go vet ./...1go doc net/http1go doc -src net/http.Client.Do1go generate ./...1go fix ./...1staticcheck ./...1go test ./...1go test -v ./...1go test -run '^TestHealth$' ./...1go test -count=1 ./...1go test -race ./...1go test -timeout 2m ./...1go test -short ./...1go test -parallel 8 ./...1go test -run '^Example' ./...1go test -json ./... > test.json1go test -cover ./...1go test -coverprofile=coverage.out ./...1go tool cover -func=coverage.out1go tool cover -html=coverage.out -o coverage.html1go test -run '^$' -bench . ./...1go test -bench . -benchmem ./...1go test -bench BenchmarkAPI -count 5 ./...1go test -bench . -benchtime=3s ./...1go test -bench . -cpuprofile cpu.out ./pkg/service1go test -bench . -memprofile mem.out ./pkg/service1go tool pprof -top cpu.out1go tool pprof -http=:8080 cpu.out1go tool pprof -top http://127.0.0.1:6060/debug/pprof/heap1go tool pprof -seconds=30 http://127.0.0.1:6060/debug/pprof/profile1go test -trace trace.out ./pkg/service1go tool trace trace.out1go build -gcflags='-m=2' ./cmd/app1go tool compile -S main.go1GODEBUG=gctrace=1 go run .1curl -s http://127.0.0.1:6060/debug/pprof/1go work init ./app ./lib1go work use ./tools1go work sync1go env GOWORK1go list ./...1go list -deps ./cmd/app1go list -json ./cmd/app1go list std | grep '^net/'1gofmt -w . && go vet ./... && go test -race ./...1go mod verify && go test ./... && CGO_ENABLED=0 go build -trimpath -ldflags='-s -w' -o bin/app ./cmd/appGo 的核心工具链高度统一。项目中应优先使用 Modules、固定工具版本、执行 go mod verify、测试与漏洞扫描,并让发布二进制具备可追溯的版本信息。