new-api

SkillDev tools

Adds a new HTTP endpoint to an existing go-zero service. Triggered when the user says add an endpoint, new API, or add a route.

Available today. Use it from your connected AI after setup.

Connect ahel once, and every AI you use reads what you have installed.

Then ask your AI: use the new-api skill

What this skill tells your AI

The instructions your AI receives, as published by iceymoss/go-hichat-api in .claude/skills/new-api/SKILL.md and read by ahel’s review.

apps/<svc>/api 里新增一个 HTTP 接口,使用 goctl 重新生成。

步骤

1. 确认输入

  • 哪个服务(apps/ 下选一个)
  • 路径与方法(如 POST /v1/im/conversation/mute
  • 是否需要 JWT
  • 请求 / 响应字段
  • 业务逻辑要不要调用某个 RPC(如果要,确认对应 xxxclient 已经注入到 svc.ServiceContext

2. 修改 .api

编辑 apps/<svc>/api/<svc>.api

  • type (...) 块里加 XxxReq / XxxResp —— 可选字段加 optional,可选标量在 Go 端用指针 + omitempty
  • 在对应 @server 块下加路由:
@doc "中文描述"
@handler xxxHandler
post /v1/<svc>/path (XxxReq) returns (XxxResp)

3. 重新生成代码

goctl api go -api apps/<svc>/api/<svc>.api -dir apps/<svc>/api -style gozero

goctl 只会生成缺失的 handler/logic 骨架,不会覆盖你已有的实现。生成完检查 internal/handler/routes.go 已加路由。

4. 写 logic

apps/<svc>/api/internal/logic/<xxx>logic.go 写业务:

  • 调用 RPC:l.svcCtx.UserRpc.GetUser(l.ctx, &user.GetUserReq{...})
  • 错误用 pkg/xerr 封装,不要返回原始 error 给客户端
  • JSON 序列化用 common.Marshal/Unmarshalgo-backend.md

5. 测试

  • 单元测试:在 internal/logic/<xxx>logic_test.go 写 table-driven 测试
  • 手工:go run apps/<svc>/api/<svc>.go -f apps/<svc>/api/etc/<svc>-sample.yaml,再 curl

6. 同步文档

/sync-api-docs 更新 docs/api.md

严格约束

  • .api必须重跑 goctl,不要手写 handler
  • 业务在 logic 层;handler 只做参数绑定 + 调 logic
  • 跨服务调用走 RPC,不要直接读对方数据库(microservice.md
  • 可选请求字段:DTO 用指针 + omitempty

Signals

GitHub stars
41
Forks
9
Last commit
Aug 2026
Advanced
Catalog kind
skill
Gateway key
new-api
Source
github.com/iceymoss/go-hichat-api