golang
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGolang Development Skill
Golang开发技能
Activation Triggers
激活触发条件
- Working with files,
.go,go.mod,go.sumgo.work - User mentions Go, Golang, or Go-specific terms
- Questions about Go libraries, frameworks, or tooling
- Concurrency patterns (goroutines, channels, context)
- 处理文件、
.go、go.mod、go.sumgo.work - 用户提及Go、Golang或Go专属术语
- 关于Go库、框架或工具的问题
- 并发模式(goroutines、channels、context)
Workflow: Research-First Approach
工作流:先调研的方法
Before implementing, gather context from authoritative sources:
undefined在实现之前,从权威来源收集相关信息:
undefinedContext7 query-docs for repo-specific docs
Context7 query-docs for repo-specific docs
query-docs({ libraryId: "/gin-gonic/gin", query: "how to set up middleware" })
query-docs({ libraryId: "/uber-go/zap", query: "structured logging setup" })
query-docs({ libraryId: "/gin-gonic/gin", query: "how to set up middleware" })
query-docs({ libraryId: "/uber-go/zap", query: "structured logging setup" })
gh search code for real-world implementation examples
gh search code for real-world implementation examples
gh search code "ratelimit.New(" --language=go
gh search code "errgroup.WithContext(" --language=go
gh search code "ratelimit.New(" --language=go
gh search code "errgroup.WithContext(" --language=go
For style/idiom questions
For style/idiom questions
query-docs({ libraryId: "/uber-go/guide", query: "style guide patterns and idioms" })
undefinedquery-docs({ libraryId: "/uber-go/guide", query: "style guide patterns and idioms" })
undefinedNotes
说明
Repository routing table lives in .
reference.md仓库路由表位于中。
reference.mdCLI Quick Reference
CLI速查参考
Module Management
模块管理
bash
go mod init <module> # Initialize module
go mod tidy # Sync dependencies
go get <pkg>@latest # Add/update dependency
go get <pkg>@v1.2.3 # Specific version
go mod download # Download dependencies
go mod why <pkg> # Why is pkg needed
go mod graph # Dependency graphbash
go mod init <module> # Initialize module
go mod tidy # Sync dependencies
go get <pkg>@latest # Add/update dependency
go get <pkg>@v1.2.3 # Specific version
go mod download # Download dependencies
go mod why <pkg> # Why is pkg needed
go mod graph # Dependency graphBuild & Run
构建与运行
bash
go build ./... # Build all packages
go run . # Run current package
go install ./cmd/... # Install binaries
go generate ./... # Run go:generate directivesbash
go build ./... # Build all packages
go run . # Run current package
go install ./cmd/... # Install binaries
go generate ./... # Run go:generate directivesTesting
测试
bash
go test ./... # Run all tests
go test -v ./... # Verbose output
go test -race ./... # Race detector
go test -cover ./... # Coverage summary
go test -coverprofile=c.out ./... && go tool cover -html=c.out # Coverage HTML
go test -bench=. ./... # Run benchmarks
go test -fuzz=FuzzXxx ./... # Fuzz testing
go test -run=TestName # Run specific test
go test -count=1 # Disable test cachingbash
go test ./... # Run all tests
go test -v ./... # Verbose output
go test -race ./... # Race detector
go test -cover ./... # Coverage summary
go test -coverprofile=c.out ./... && go tool cover -html=c.out # Coverage HTML
go test -bench=. ./... # Run benchmarks
go test -fuzz=FuzzXxx ./... # Fuzz testing
go test -run=TestName # Run specific test
go test -count=1 # Disable test cachingLinting (golangci-lint)
代码检查(golangci-lint)
bash
golangci-lint run # Run all linters
golangci-lint run --fix # Auto-fix issues
golangci-lint linters # List available lintersbash
golangci-lint run # Run all linters
golangci-lint run --fix # Auto-fix issues
golangci-lint linters # List available lintersWorkspaces (multi-module)
工作区(多模块)
bash
go work init ./mod1 ./mod2 # Initialize workspace
go work use ./mod3 # Add module to workspace
go work sync # Sync workspacebash
go work init ./mod1 ./mod2 # Initialize workspace
go work use ./mod3 # Add module to workspace
go work sync # Sync workspaceOther Tools
其他工具
bash
go fmt ./... # Format code
go vet ./... # Static analysis
go doc <pkg> # View documentation
go env # Environment variables
go version # Go versionbash
go fmt ./... # Format code
go vet ./... # Static analysis
go doc <pkg> # View documentation
go env # Environment variables
go version # Go versionFiles
文件
- - Go 1.24+ features, project layout, Uber style highlights
reference.md - - Table-driven tests, testify, mocking, benchmarks
cookbook/testing.md - - Goroutines, channels, context, errgroup
cookbook/concurrency.md - - Functional options, DI, error handling
cookbook/patterns.md
- - Go 1.24+特性、项目布局、Uber风格要点
reference.md - - 表驱动测试、testify、Mocking、基准测试
cookbook/testing.md - - Goroutines、Channels、Context、errgroup
cookbook/concurrency.md - - 函数选项模式、依赖注入、错误处理
cookbook/patterns.md