SuperAPI AI 工具集

moai-lang-go

编程与开发

查看项目

更新于 10-16 09:59

技能介绍

用途:面向 Go 1.23+ 的高性能后端系统与 CLI 应用开发。当出现 .go 文件、go.mod、go.sum,或涉及 goroutine、channel、Fiber、Gin、GORM、Echo、Chi 等关键词时自动触发。

主要能力:

  1. Web 框架。Fiber v3(fiber.New、中间件 recover/logger/cors、api 分组路由、app.Listen);Gin(gin.Default、路由与 c.JSON、r.Run);Echo(echo.New、middleware.Logger/Recover/CORS、e.Start);Chi(chi.NewRouter、r.Route 嵌套路由、http.ListenAndServe)。
  2. 请求绑定。结构体加 json 与 binding 标签(required、min、email 校验),用 c.ShouldBindJSON 解析并返回 400/201。
  3. ORM。GORM 1.25:gorm.Model 嵌入、uniqueIndex/not null 标签、Preload 关联查询、db.Transaction 事务。
  4. 类型安全 SQL。sqlc.yaml(version 2、postgresql 引擎、go 生成配置、pgx v5),query.sql 中命名查询。
  5. 并发。errgroup.WithContext 并行任务、worker pool(jobs/results channel 加 WaitGroup)、context.WithTimeout 与 DeadlineExceeded 处理。
  6. 泛型与语言特性:range over integers、PGO 2.0、泛型 Map 等类型推断模式。
  7. 测试:表驱动测试、httptest 与 fiber app.Test 做 HTTP 测试。
  8. CLI:Cobra 定义 rootCmd、PersistentFlags,Viper 绑定配置与 AutomaticEnv。
  9. 性能与部署:PGO 构建、sync.Pool 对象池、多阶段 Dockerfile 生成 10-20MB 镜像、优雅关闭(signal.Notify 后 app.Shutdown)。

使用方式:按资料中的模式代码组织项目,可配合 moai-domain-backend、moai-lang-rust、moai-quality-security、moai-essentials-debug、moai-workflow-ddd 使用。高级并发、泛型、接口设计与测试细节见 reference/advanced.md 与 reference/testing.md。

限制:未提供收费、价格、平台与效果数据;资料中的版本号与演示端口、代码片段应结合实际情况调整。常见问题排查:go mod tidy 与 go mod verify 处理模块错误,go version 与 go env GOVERSION 检查版本,go clean -cache 与 go build -v 处理构建问题;性能诊断可用 go test -cpuprofile、-memprofile、-race。