middleware-go

Create Go HTTP middlewares for authentication, signature verification, and session resolution.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Go backends need cross-cutting concerns like signature verification, API key auth, and session resolution to run before controllers, but inconsistent middleware implementations lead to rejected requests falling through, raw error responses, and misplaced business logic. ## Core Features & Use Cases - Standard Middleware Shape: Generates factory functions returning func(next http.Handler) http.Handler that capture config like secrets or DB clients via closures. - Guard and Enrichment Patterns: Covers rejecting middlewares (HMAC signature, API key) and pass-through enriching middlewares (session cookie to X-Owner-Id header injection). - Wiring and Placement Rules: Attaches middlewares via ControllerMetadata.Middlewares per controller or at router level, with clear shared vs context-local directory conventions. - Use Case: When adding a webhook endpoint that receives transcoder callbacks, generate a VerifyTranscoderSignature middleware that rejects invalid signatures with a typed 401 error before the controller runs. ## Quick Start Ask the agent to create a Go HTTP middleware that validates an API key header and wires it into the controller metadata for your endpoint.

Frequently Asked Questions about middleware-go

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

FAQPage Schema
How do I write an HTTP middleware in Go?

Write a factory function that accepts config like secrets and returns func(next http.Handler) http.Handler. Inside, wrap an http.HandlerFunc that either rejects with httputil.RespondError and returns, or calls next.ServeHTTP to pass the request through.

How do I validate an API key header in Go middleware?

Read the header with r.Header.Get("apikey"), compare it against the configured key, and on mismatch call httputil.RespondError with errors.NewBaseError(errors.CodeUnauthorized, msg) then return. On match, call next.ServeHTTP.

How do I attach middleware to specific routes in Go?

Attach middlewares per controller through the ControllerMetadata.Middlewares slice, which the router applies in order around the controller's Handle method. Global middlewares like logging or recovery are wired at the router level instead.

Should session middleware reject unauthenticated requests?

No. Enriching middlewares like session resolution never reject; they resolve the owner ID from the session cookie, inject it as an X-Owner-Id header when found, and always call next.ServeHTTP. Downstream controllers handle missing identity.

When should logic not go in an HTTP middleware?

Keep business validation, per-endpoint input parsing, and post-success side effects out of middleware. Business rules belong in use cases or entities, input validation in controller struct tags, and post-success effects in event handlers.