go-api
Skill1 starsChanged 6 months agoMITView on GitHub
Use for Golang web API work — enforces handler/service/repo layering, error wrapping, interfaces, context propagation, and no global state.
In this repository10 other files it gives its agents.
- api-designSkill
- brainstormSkill
- code-reviewSkill
- commitSkill
- evaluate-feedbackSkill
- multi-agentSkill
- planSkill
- tddSkill
- ts-apiSkill
- workflowSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
18 rules. About 0 are common, 8 are distinctive, and 10 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈8
Distinctive · estimate
This author's own choices. Worth a look.
10
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 48
Always wrap errors with context:
- Very specific: line 71
Use errors.Is() and errors.As() in handlers to map to HTTP status codes — never do this in services.
- Very specific: line 99
Use context.WithTimeout for external calls
- Very specific: line 103
Prefer net/http stdlib + chi router
- Distinctive: line 104
Avoid heavy frameworks (no gin, no echo — keep it replaceable)
- Very specific: line 105
Use chi.URLParam(r, "id") for path params
- Very specific: line 110
Use go-playground/validator struct tags:
- Distinctive: line 129
Use a shared package — never build envelope inline:
- Very specific: line 139
Use log/slog (stdlib, Go 1.21+):
- Very specific: line 157
Use errgroup.Group for parallel work with error aggregation
- Distinctive: line 158
Avoid raw goroutines without a WaitGroup or channel for synchronization
- Very specific: line 159
Always pass context.Context to goroutine work for cancellation
- Distinctive: line 163
No global variables for dependencies (db, logger, config) — inject via structs
- Very specific: line 164
No bare errors.New("something") in service or repository without wrapping caller context
- Distinctive: line 165
No business logic in handlers
- Distinctive: line 166
No SQL in services
- Very specific: line 168
No heavy frameworks replacing net/http
- Distinctive: line 169
Never discard context — always propagate
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Golang Web API
Conventions for Go web API development. These apply for the entire session once activated.
Recommended model: Sonnet
Includes all standards from the api-design skill.
Package and Layer Structure
Three layers per feature, each in its own file:
internal/
users/
handler.go # HTTP: parse request, call service, write response
service.go # Business logic: no HTTP, no SQL
repository.go # DB: raw queries only
types.go # Domain types, request/response structs
shared/
response/
response.go # JSON response helpers
middleware/
auth.go
logging.go
errors/
errors.go # AppError, sentinel errors
cmd/
api/
main.goHandler (thin): Decode request → validate → call service → encode response. No business logic.
Service: Pure business rules. No http.Request/http.ResponseWriter. No SQL. Returns domain types and errors.
Repository: SQL/DB only. No business rules. Takes context.Context as first arg.
Error Handling
Always wrap errors with context:
// In repository
return nil, fmt.Errorf("userRepo.FindByID: %w", err)
// In service
return nil, fmt.Errorf("userService.GetUser: %w", err)Define typed errors for domain conditions:
var ErrNotFound = errors.New("not found")
var ErrConflict = errors.New("conflict")
type ValidationError struct {
Field string
Message string
}
func (e *ValidationError) Error() string { return fmt.Sprintf("%s: %s", e.Field, e.Message) }Use errors.Is() and errors.As() in handlers to map to HTTP status codes — never do this in services.
Interfaces and Dependency Injection
- Accept interfaces, return concrete types
- Define interfaces where they are used (not where implemented)
- Inject all dependencies via struct fields; no global state
type UserRepository interface {
FindByID(ctx context.Context, id string) (*User, error)
Create(ctx context.Context, input CreateUserInput) (*User, error)
}
type UserService struct {
repo UserRepository
logger *slog.Logger
}
func NewUserService(repo UserRepository, logger *slog.Logger) *UserService {
return &UserService{repo: repo, logger: logger}
}Context
context.Contextis the first parameter of every service and repository method- Propagate context from handler through to DB call — never discard it
- Use
context.WithTimeoutfor external calls
HTTP Layer
- Prefer
net/httpstdlib +chirouter - Avoid heavy frameworks (no gin, no echo — keep it replaceable)
- Use
chi.URLParam(r, "id")for path params - Decode JSON body:
json.NewDecoder(r.Body).Decode(&input)— always check error
Validation
Use go-playground/validator struct tags:
type CreateUserInput struct {
Email string `json:"email" validate:"required,email"`
Name string `json:"name" validate:"required,min=1,max=100"`
}Validate in handler before calling service:
if err := validate.Struct(input); err != nil {
// map to 400 response
}Response Helpers
Use a shared package — never build envelope inline:
// internal/shared/response/response.go
func JSON(w http.ResponseWriter, status int, data any) { ... }
func Error(w http.ResponseWriter, status int, code, message string) { ... }Logging
Use log/slog (stdlib, Go 1.21+):
slog.InfoContext(ctx, "user created", "userID", user.ID, "requestID", r.Header.Get("X-Request-Id"))Log at service/handler boundary only. Repositories should not log.
Graceful Shutdown
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
// start server, then wait on ctx.Done()Concurrency
- Use
errgroup.Groupfor parallel work with error aggregation - Avoid raw goroutines without a WaitGroup or channel for synchronization
- Always pass
context.Contextto goroutine work for cancellation
What NOT to do
- No global variables for dependencies (db, logger, config) — inject via structs
- No bare
errors.New("something")in service or repository without wrapping caller context - No business logic in handlers
- No SQL in services
- No
http.Requestpassed to services - No heavy frameworks replacing
net/http - Never discard context — always propagate
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

