controller-go

Implements Go HTTP controllers with fx auto-registration, request decoding, and OpenAPI metadata.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill controller-go-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: controller-go
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/controller/go
Command: npx skills add https://github.com/gabriellst/codm --skill controller-go-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing Go HTTP controllers by hand often leads to inconsistent route registration, missing OpenAPI schemas, unvalidated requests, and business logic leaking into handlers. This Skill standardizes how controllers are defined, registered, and wired to use cases in an fx-based Go backend. ## Core Features & Use Cases - Declarative route metadata: Implements types.Controller with Metadata() and Handle(), so routes, methods, middlewares, and OpenAPI schemas are declared in one place. - Auto-registration via fx: Controllers are registered with fx.As(new(types.Controller)) and fx.ResultTags(group:"controllers"), letting the HTTP router discover them automatically. - Request decoding and validation: Uses httputil.DecodeRequest with from, validate, and swaggerignore struct tags, plus validator/v10 under the hood. - Use Case: Add a new POST /api/v1/channel/channels/whatsapp endpoint by defining a request struct, a thin controller that dispatches to a use case handler, and one fx registration line in module.go. ## Quick Start Ask the agent to create a new Go controller for a specific endpoint in a bounded context, following the controller-go patterns and registering it in module.go.

Frequently Asked Questions about controller-go

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

FAQPage Schema
How do I create a Go HTTP controller with fx auto-registration?

Define a struct implementing Metadata() and Handle(w, r), then register it in module.go with fx.Provide(fx.Annotate(NewXController, fx.As(new(types.Controller)), fx.ResultTags(`group:"controllers"`))). The HTTP router collects the group and builds routes from Metadata().

How do I validate request bodies in a Go controller?

Call httputil.DecodeRequest[YourRequest](r) as the first step in Handle and return immediately on error. DecodeRequest runs validator/v10 internally using the `validate` struct tags, so invalid input never reaches the use case.

How do I bind path parameters in Go 1.22 HTTP handlers?

Declare path params as request struct fields tagged `from:"param" name:"id"` and let httputil.DecodeRequest read them via r.PathValue. Avoid manually splitting r.URL.Path, which breaks when route prefixes change.

Why is my endpoint missing from the generated OpenAPI spec?

The reflection-based OpenAPI emitter reads Metadata().Request and Metadata().Response zero values. If either is omitted, no schema is generated; set Request to your request struct and Response to the use case output zero value, or nil for 204.

How do I make a Go controller route public and skip auth middleware?

Set Public: true on ControllerMetadata. This skips only the global middleware chain applied by RegisterControllers while the controller's own Middlewares still run; never register the route directly on the mux to bypass auth.

When should middleware go in Metadata instead of inside Handle?

Always declare per-controller middleware in Metadata().Middlewares so the router wraps the handler before registration. Inline middleware logic inside Handle bypasses the router's wrapping and mixes cross-cutting concerns into the handler body.