go-http-server-routes

Define method-aware HTTP routes with wildcard patterns for Go 1.22+ net/http ServeMux.

130|8|Updated Jan 23, 2026
One-click install
npx skills add https://github.com/sandgardenhq/sgai --skill go-http-server-routes
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-http-server-routes
Source: https://github.com/sandgardenhq/sgai/tree/main/cmd/sgai/skel/.sgai/skills/coding-practices/go-http-server-routes
Command: npx skills add https://github.com/sandgardenhq/sgai --skill go-http-server-routes

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The skill addresses the difficulty of defining concise, method-aware routes and complex path patterns in Go's standard net/http ServeMux before Go 1.22, which required manual parsing and custom logic.

Core Features & Use Cases

  • Method matching: Prefix routes with HTTP verbs (GET, POST, etc.) directly in patterns.
  • Single-segment and multi-segment wildcards: {id} and {path...} to capture variables.
  • Exact trailing-slash matching using {$} for precise endpoint control.
  • Precedence and conflict detection ensures deterministic routing and panics on ambiguous patterns.
  • Use case: Build a RESTful API with CRUD endpoints such as GET /api/posts/{id}, POST /api/posts, PUT /api/posts/{id}, DELETE /api/posts/{id} without external routers.

Quick Start

Ask the AI to generate a Go HTTP server that uses the new routing syntax to provide CRUD endpoints for a “posts” resource.

Frequently Asked Questions about go-http-server-routes

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

FAQPage Schema
How do I define method-aware HTTP routes in Go using net/http ServeMux?

Method-aware HTTP routing in Go's standard ServeMux uses HTTP verb prefixes like GET or POST directly in route patterns. This enables RESTful endpoint definition without external routers, available natively in Go 1.22+.

Can I use wildcards for path parameters in the Go standard ServeMux?

Yes, Go ServeMux supports single-segment wildcards like {id} and multi-segment wildcards like {path...} to capture URL variables. These patterns allow dynamic path matching for resources in Go 1.22+.

Do I need an external router to build a RESTful API in Go?

No, building a RESTful API in Go does not require external routers when using Go 1.22+. The standard net/http ServeMux supports method matching, wildcards, and precedence handling for CRUD endpoints.

How does Go ServeMux handle conflicting route patterns?

Go ServeMux ensures deterministic routing through automatic precedence handling and panics on ambiguous or conflicting patterns. This strict conflict detection prevents unpredictable routing behavior during server setup.

How do I match exact trailing slashes in Go HTTP routing?

Exact trailing-slash matching in Go HTTP routing uses the {$} wildcard syntax for precise endpoint control. This ensures patterns match only the specified path without unintended subtree collisions.