KS
Killer-Skills

http-patterns — http-patterns Go 1.22 http-patterns Go 1.22, how to use http-patterns, Go ServeMux method routing, http-patterns path parameters, http-patterns vs gorilla mux, http-patterns setup guide, Go 1.22 HTTP handler patterns, r.PathValue example, what is http-patterns, http-patterns install

v1.0.0
GitHub

About this Skill

Ideal for Go-based AI Agents needing structured HTTP handler patterns for method-based routing and path parameters. http-patterns is a Go package providing project-specific conventions and patterns for HTTP handlers. It leverages Go 1.22's enhanced http.ServeMux to enable declarative routing with HTTP verb prefixes and built-in path parameter extraction.

Features

Go 1.22 ServeMux Method Routing using HTTP verb prefixes (e.g., 'GET /healthz')
Eliminates manual HTTP method checks within handler functions
Native path parameter extraction via r.PathValue()
Supports wildcard path segments using the '{path...}' syntax
Functions as a rendering proxy to serve raw documents as styled HTML

# Core Topics

air-gapped air-gapped
[0]
[0]
Updated: 3/6/2026

Quality Score

Top 5%
30
Excellent
Based on code quality & docs
Installation
SYS Universal Install (Auto-Detect)
Cursor IDE Windsurf IDE VS Code IDE
> npx killer-skills add air-gapped/cooked/http-patterns

Agent Capability Analysis

The http-patterns MCP Server by air-gapped is an open-source Categories.community integration for Claude and other AI agents, enabling seamless task automation and capability expansion. Optimized for http-patterns Go 1.22, how to use http-patterns, Go ServeMux method routing.

Ideal Agent Persona

Ideal for Go-based AI Agents needing structured HTTP handler patterns for method-based routing and path parameters.

Core Value

Empowers agents to handle HTTP requests with Go 1.22+ HTTP handler patterns, providing a structured way to implement method-based routing and path parameters using HTTP verb prefix registration and ServeMux.

Capabilities Granted for http-patterns MCP Server

Implementing method-based routing for web services
Handling path parameters for proxies and web applications
Building scalable HTTP handlers with Go 1.22+ patterns

! Prerequisites & Limits

  • Requires Go 1.22+ for HTTP handler pattern support
  • Limited to Go-based applications and services
Project
SKILL.md
5.4 KB
.cursorrules
1.2 KB
package.json
240 B
Ready
UTF-8

# Tags

[No tags]
SKILL.md
Readonly

HTTP Patterns

Go 1.22+ patterns and project-specific conventions for HTTP handlers.


Go 1.22: ServeMux Method Routing

No more manual method checks. Register with HTTP verb prefix:

go
1mux := http.NewServeMux() 2mux.HandleFunc("GET /healthz", healthHandler) 3mux.HandleFunc("GET /_cooked/{path...}", assetHandler) 4mux.HandleFunc("GET /{upstream...}", renderHandler)

Path Parameters

go
1func renderHandler(w http.ResponseWriter, r *http.Request) { 2 upstream := r.PathValue("upstream") // NEW in Go 1.22 3 // ... 4}

Special Patterns

PatternMatches
/posts/{id}/posts/123 (single segment)
/files/{path...}/files/a/b/c (remainder of path)
/posts/{$}/posts/ only (not /posts or /posts/x)

Precedence

More specific wins:

  • /healthz beats /{upstream...}
  • GET /posts/{id} beats /posts/{id}

Conflicting patterns panic at registration:

go
1mux.HandleFunc("GET /posts/{id}", h1) 2mux.HandleFunc("GET /{resource}/latest", h2) // PANIC - both match /posts/latest

Automatic 405

Unmatched methods return 405 Method Not Allowed with Allow header.

go.mod Requirement

Go 1.22+ patterns require go 1.22 or later in go.mod. Without it, patterns are treated literally (braces aren't wildcards).

Sources: Go Blog: Routing Enhancements, Eli Bendersky


Middleware Pattern

This project uses the standard wrapper pattern:

go
1func RequestLogger(next http.Handler) http.Handler { 2 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 3 start := time.Now() 4 wrapped := &byteCountingWriter{ResponseWriter: w} 5 next.ServeHTTP(wrapped, r) 6 slog.Info("request", 7 "method", r.Method, 8 "path", r.URL.Path, 9 "status", wrapped.statusCode, 10 "bytes", wrapped.bytes, 11 "total_ms", time.Since(start).Milliseconds(), 12 ) 13 }) 14} 15 16// Composable 17var handler http.Handler = mux 18handler = RequestLogger(handler) 19handler = RecoveryMiddleware(handler) 20 21srv := &http.Server{Handler: handler}

Request Context

Store request-scoped values using typed keys:

go
1// Define typed key (prevents collisions) 2type contextKey string 3const loggerKey contextKey = "logger" 4 5// Set in middleware 6ctx := context.WithValue(r.Context(), loggerKey, logger) 7next.ServeHTTP(w, r.WithContext(ctx)) 8 9// Retrieve in handlers 10func Logger(ctx context.Context) *slog.Logger { 11 if l, ok := ctx.Value(loggerKey).(*slog.Logger); ok { 12 return l 13 } 14 return slog.Default() 15}

ResponseWriter Wrapping

Wrap to capture bytes and status:

go
1type byteCountingWriter struct { 2 http.ResponseWriter 3 bytes int64 4 statusCode int 5} 6 7func (w *byteCountingWriter) WriteHeader(code int) { 8 w.statusCode = code 9 w.ResponseWriter.WriteHeader(code) 10} 11 12func (w *byteCountingWriter) Write(b []byte) (int, error) { 13 if w.statusCode == 0 { 14 w.statusCode = 200 // Default if WriteHeader not called 15 } 16 n, err := w.ResponseWriter.Write(b) 17 w.bytes += int64(n) 18 return n, err 19}

Graceful Shutdown

Standard Pattern

go
1srv := &http.Server{ 2 Addr: ":8080", 3 Handler: mux, 4} 5 6// Start server 7go func() { 8 if err := srv.ListenAndServe(); !errors.Is(err, http.ErrServerClosed) { 9 log.Fatal(err) 10 } 11}() 12 13// Wait for signal 14<-ctx.Done() 15 16// Graceful shutdown with timeout 17shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) 18defer cancel() 19 20if err := srv.Shutdown(shutdownCtx); err != nil { 21 log.Printf("shutdown error: %v", err) 22}

What Shutdown() Does

  1. Stops accepting new connections immediately
  2. Closes idle connections
  3. Waits for active requests to complete
  4. Returns when all handlers finish OR context expires

Kubernetes Considerations

Add a health endpoint that fails during shutdown:

go
1healthService.MarkShuttingDown() // Called before Shutdown() 2// Readiness probe now returns 503

Sources: VictoriaMetrics, DEV Community


Error Responses

cooked returns HTML error pages, not JSON:

go
1func renderError(w http.ResponseWriter, r *http.Request, status int, errType, message string) { 2 w.Header().Set("Content-Type", "text/html; charset=utf-8") 3 w.WriteHeader(status) 4 // Render error template with same theming as content pages 5}

Error pages use the same HTML template with:

  • Proper theming (respects user's theme choice)
  • #cooked-error element with data-error-type and data-status-code
  • Direct link to the upstream URL

Handler Naming

PatternReturnsExample
FeatureHandler(deps)http.HandlerFuncRenderHandler(deps)
FeatureMiddleware(next)http.HandlerRequestLogger(next)

What NOT to Do

Don'tWhy
Check method with if r.Method != "GET"Use Go 1.22+ method routing
Call w.Write after handler returnsCauses panic or writes to wrong response
Use string context keysCollisions — use typed keys
Ignore http.ErrServerClosedIt's expected from Shutdown()
Release resources before shutdown completesHandlers may still be using them

Related Skills

Looking for an alternative to http-patterns or building a Categories.community AI Agent? Explore these related open-source MCP Servers.

View All

widget-generator

Logo of f
f

widget-generator is an open-source AI agent skill for creating widget plugins that are injected into prompt feeds on prompts.chat. It supports two rendering modes: standard prompt widgets using default PromptCard styling and custom render widgets built as full React components.

149.6k
0
Design

chat-sdk

Logo of lobehub
lobehub

chat-sdk is a unified TypeScript SDK for building chat bots across multiple platforms, providing a single interface for deploying bot logic.

73.0k
0
Communication

zustand

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication

data-fetching

Logo of lobehub
lobehub

The ultimate space for work and life — to find, build, and collaborate with agent teammates that grow with you. We are taking agent harness to the next level — enabling multi-agent collaboration, effortless agent team design, and introducing agents as the unit of work interaction.

72.8k
0
Communication