workflows.md- Task patternstools.md- goctl commandspatterns.md- Code patterns- zero-skills - Detailed patterns (查阅详细模式)
- ALWAYS create
.apispec before code - Write spec following patterns in
patterns.md - Validate with
goctl api validate
- Use goctl commands in terminal, NOT manual code generation
goctl api newfor new API servicesgoctl rpc new/goctl rpc protocfor new RPC servicesgoctl api gofor code from specgoctl model mysql/pg/mongofor database models- Always run post-generation steps:
go mod tidy→ verify imports →go build ./... - If goctl is not installed, install it:
go install github.com/zeromicro/go-zero/tools/goctl@latest
- Generate FULL implementation, not stubs
- Fill logic layer with business code
- Add validation tags:
validate:"required,email" - Generate tests automatically
- ALWAYS generate README.md for new services
- Service overview and purpose
- API/RPC endpoint documentation
- Configuration guide
- Usage examples with curl/grpcurl
- Testing instructions
- Generate API.md/RPC.md for detailed endpoint docs
- Include request/response examples
- Document error codes and handling
- Context first:
func(ctx context.Context, req *types.Request) - Errors:
errorx.NewCodeError(code, msg) - Config:
json:",default=value" - Validation:
validate:"required,min=3"
User Request →
├─ New API? → Write .api spec → goctl api go → go mod tidy → go build → Generate docs
├─ New RPC? → Write .proto → goctl rpc protoc → go mod tidy → go build → Generate docs
├─ Database? → goctl model mysql/pg/mongo
└─ Modify? → Edit .api → goctl api go → go mod tidy → go build → Update docs
For complete implementation patterns, refer to zero-skills:
- REST API → rest-api-patterns.md
- RPC Services → rpc-patterns.md
- Database → database-patterns.md
- Resilience → resilience-patterns.md
- goctl Commands → goctl-commands.md
- Troubleshooting → common-issues.md
- Empty stubs
- Missing validation
fmt.Errorffor API errors (useerrorx.NewCodeError)- Manual SQL (use
goctl model) - Missing context
- Skipping post-generation steps (mod tidy, build verify)
- Mismatched
--styleflag with existing code