go-api-handlers

Writes Gin HTTP handlers following clean-architecture conventions for Go API layers.

2|Updated Sep 2, 2022
One-click install
npx skills add https://github.com/silvioubaldino/personal-finance --skill go-api-handlers-silvioubaldino
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: go-api-handlers
Source: https://github.com/silvioubaldino/personal-finance/tree/main/.claude/skills/go-api-handlers
Command: npx skills add https://github.com/silvioubaldino/personal-finance --skill go-api-handlers-silvioubaldino

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing HTTP handlers in a clean-architecture Go codebase often leads to inconsistent patterns: business logic leaking into handlers, ad-hoc error responses, and wrong status codes. This Skill enforces a single authoritative style for Gin handlers in internal/infrastructure/api/*_api.go so every endpoint parses input, calls a usecase, and shapes responses the same way. ## Core Features & Use Cases - Handler scaffolding: Generates a complete *_api.go file with a narrow usecase interface declared in-file, a handler struct, and a New{Feature}V2Handlers constructor that registers all routes under a /v2/{feature} group. - Convention enforcement: Applies strict rules for input parsing (uuid path params, optional query params guarded on empty string, JSON bound directly into domain types), error handling via HandleErr, and status-code selection (201 for creation, 200 for returned resources, 204 for no body). - Use Case: When adding a new endpoint like POST /v2/widgets/:id/pay, the Skill produces a handler closure that parses the path param and optional date query param, delegates to the usecase, and returns the mapped output with the correct status code. ## Quick Start Ask the AI to add a new Gin endpoint to an existing feature API file following the go-api-handlers conventions.

Frequently Asked Questions about go-api-handlers

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a new endpoint to a Gin handler in clean architecture?▼

Add a method to the feature's usecase interface in the handler file, write a route method returning gin.HandlerFunc, and register it in the New{Feature}V2Handlers constructor. The closure parses input, calls the usecase, and shapes the response with no business logic.

How should Gin handlers handle errors in Go?▼

Pass every parsing or usecase error to HandleErr(c, ctx, err) followed by a bare return. Never hand-build JSON error bodies in handlers; the errors_handler.go toAPIError function owns the status code mapping, and new sentinel errors get a case added there.

Should Gin handlers import concrete usecase structs?▼

No. Declare a narrow {Feature}Usecase interface inside the handler file listing only the methods the handler calls, and depend on that interface. The concrete usecase is injected via the constructor and wired in bootstrap/{feature}/setup.go.

What HTTP status code should a Gin endpoint return?▼

Status follows the outcome: 201 Created with a body for new resources, 200 OK with a body when returning the affected resource, and 204 No Content with no body when nothing is returned, such as deletes.

How do I parse optional query params in Gin without errors?▼

Guard on an empty string before parsing so an absent param leaves the zero value instead of erroring. Only parse and wrap errors with domain.WrapInvalidInput when the param is actually present.