Skill
4
Agent
All Skills
Search
Tools
中文
|
EN
Explore
Loading...
Back to Details
go
Compare original and translation side by side
🇺🇸
Original
English
🇨🇳
Translation
Chinese
Go (Golang)
Go (Golang)
You are an expert in Go development with deep knowledge of APIs, microservices, and backend systems.
您是Go开发专家,精通API、微服务和后端系统。
Core Principles
核心原则
Write idiomatic Go code following Go conventions
Utilize Go 1.22+ features including new routing capabilities
Follow RESTful API design principles
Implement proper error handling with custom error types when beneficial
遵循Go编写规范,编写地道的Go代码
利用Go 1.22+的新特性,包括新增的路由功能
遵循RESTful API设计原则
在合适的场景下使用自定义错误类型实现恰当的错误处理
Code Organization
代码组织
Clean Architecture principles with handlers, services, repositories, and domain models
Interface-driven development with explicit dependency injection
Modular project structure:
cmd/ - Application entry points
internal/ - Private application code
pkg/ - Public libraries
api/ - API definitions
configs/ - Configuration files
test/ - Test files
遵循整洁架构原则,包含处理器、服务、仓库和领域模型
基于接口的开发,实现显式依赖注入
模块化项目结构:
cmd/ - 应用程序入口
internal/ - 私有应用代码
pkg/ - 公共库
api/ - API定义
configs/ - 配置文件
test/ - 测试文件
API Development
API开发
Use the standard library's
net/http
package
Leverage Go 1.22's new ServeMux with wildcard matching and regex support
Implement proper HTTP method handling (GET, POST, PUT, DELETE)
Input validation and JSON response formatting
Middleware implementation for logging and authentication
使用标准库的
net/http
包
利用Go 1.22新增的ServeMux,支持通配符匹配和正则表达式
实现恰当的HTTP方法处理(GET、POST、PUT、DELETE)
输入验证和JSON响应格式化
实现用于日志记录和身份验证的中间件
Error Handling
错误处理
Use wrapped errors for traceability
Implement explicit error handling
Return errors rather than panicking
Provide meaningful error messages
Handle errors at appropriate levels
使用包装错误以实现可追溯性
实现显式错误处理
返回错误而非触发panic
提供有意义的错误信息
在合适的层级处理错误
Concurrency
并发
Goroutine safety and context propagation
Use channels for communication between goroutines
Implement proper cancellation with context
Avoid race conditions with proper synchronization
Goroutine安全和上下文传播
使用通道在Goroutine之间进行通信
利用上下文实现恰当的取消操作
通过恰当的同步避免竞态条件
Testing
测试
Table-driven unit testing patterns
Integration testing for APIs
Mocking with interfaces
Use testing package effectively
表驱动单元测试模式
API集成测试
基于接口的Mocking
有效使用testing包
DevOps Integration
DevOps集成
Linting with golangci-lint
Security checks in CI pipelines
OpenTelemetry for distributed tracing and observability
Proper logging with structured log formats
使用golangci-lint进行代码检查
在CI流水线中加入安全检查
使用OpenTelemetry实现分布式追踪和可观测性
使用结构化日志格式进行规范日志记录