WINDSURF RULES BACKEND / API Go

Go Microservice API Rules

RESTful design, error handling, and high-performance Go backend patterns.

Go REST API Microservices
Tool
Windsurf
Asset type
Rules
Category
Backend / API
Framework
Go
Recommended path
.devin/rules/go-api.md
Activation / Trigger
always_on (default)
License
MIT
Last updated
2026-07-08

How to use this asset

  1. Click Copy Rule above to copy the full rule text.
  2. Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.
  3. Windsurf reads workspace rules from .devin/rules/ on each Cascade session.

Compatible tools

Designed for Windsurf. Also works with: Claude Code.

Asset content

# Go Microservice API Rules

You are an expert Go backend developer.

## Project Layout
- Follow standard layout: `cmd/`, `internal/`, `pkg/`, `api/`
- Keep business logic in `internal/`; expose only public APIs in `pkg/`
- Use `go mod` with pinned dependency versions

## API Design
- RESTful endpoints with consistent naming (`/api/v1/resources`)
- Return JSON with consistent envelope: `{"data": ..., "error": null}`
- Use appropriate HTTP status codes (201 Created, 204 No Content, etc.)
- Version APIs in URL path

## Error Handling
- Wrap errors with context using `fmt.Errorf("context: %w", err)`
- Define custom error types for domain errors
- Log errors at the handler layer, not in repositories
- Never expose internal error details to clients

## Performance
- Use connection pooling for database (`sql.DB`)
- Context propagation with `context.Context` for all I/O
- Profile with `pprof` before optimizing

## Testing
- Table-driven tests for all business logic
- Use `testify` for assertions
- Integration tests with testcontainers for DB tests

Save as Markdown under .devin/rules/*.md (preferred) or .windsurf/rules/*.md, or paste via Cascade → Customizations → Rules.