一键导入
go-http-server-routes
Go 1.22+ enhanced HTTP routing with method matching and wildcards. When defining HTTP routes using net/http ServeMux in Go 1.22+
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Go 1.22+ enhanced HTTP routing with method matching and wildcards. When defining HTTP routes using net/http ServeMux in Go 1.22+
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Go code review checklist based on official Go style guides. When reviewing Go code for style, idioms, and best practices
Guide for creating custom opencode agents with proper configuration, permissions, path-based delegation, work splitting, and strict status envelopes. Use when creating or updating agents for coordination, implementation, review, deployment, verification, documentation, or specialized workflows.
TDD for process documentation - test with subagents before writing, iterate until bulletproof. When you discover a technique, pattern, or tool worth documenting for reuse. When editing existing skills. When asked to modify skill documentation. When you've written a skill and need to verify it works before deploying. When skills fail to help agents, when documentation is unclear, when new patterns emerge that need standardization.
Create and setup a new OpenAI Agents SDK application with interactive guidance for language choice, agent type selection (Basic, Voice, Realtime), project setup, and automatic verification.
Create and setup a new Claude Agent SDK application with interactive guidance for language choice, project setup, and automatic verification.
Problem-Solving Dispatch; Dispatch to the right problem-solving technique based on how you're stuck; Stuck on a problem. Conventional approaches not working. Need to pick the right problem-solving technique. Not sure which skill applies.
| name | go-http-server-routes |
| description | Go 1.22+ enhanced HTTP routing with method matching and wildcards. When defining HTTP routes using net/http ServeMux in Go 1.22+ |
| metadata | {"languages":"go"} |
Enhanced routing patterns for net/http.ServeMux introduced in Go 1.22.
Specify HTTP methods directly in patterns:
mux := http.NewServeMux()
mux.HandleFunc("GET /posts/{id}", getPost)
mux.HandleFunc("POST /posts", createPost)
mux.HandleFunc("PUT /posts/{id}", updatePost)
mux.HandleFunc("DELETE /posts/{id}", deletePost)
GET also matches HEAD requests405 Method Not Allowed with Allow header{name}Matches exactly one path segment:
mux.HandleFunc("GET /users/{id}", func(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
fmt.Fprintf(w, "User ID: %s", id)
})
{name...}Matches all remaining path segments:
mux.HandleFunc("GET /files/{pathname...}", func(w http.ResponseWriter, r *http.Request) {
pathname := r.PathValue("pathname")
// /files/docs/readme.txt -> pathname = "docs/readme.txt"
})
{$}Matches only the path with trailing slash:
mux.HandleFunc("GET /posts/{$}", listPosts) // matches /posts/ only
mux.HandleFunc("GET /posts/{id}", getPost) // matches /posts/123
| Pattern | Matches | Does Not Match |
|---|---|---|
/posts/{$} | /posts/ | /posts, /posts/123 |
/posts/ | /posts/, /posts/123, /posts/a/b | /posts |
/posts/{id} | /posts/123 | /posts/, /posts/a/b |
Extract wildcard values from requests:
func getPost(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
// use id...
}
For third-party routers to integrate:
r.SetPathValue("id", "123")
The most specific pattern wins. A pattern is more specific if it matches a strict subset of requests.
| Pattern A | Pattern B | Winner | Reason |
|---|---|---|---|
/posts/latest | /posts/{id} | A | Literal matches fewer requests |
GET /posts/{id} | /posts/{id} | A | Method constraint is more specific |
/users/{u}/posts/latest | /users/{u}/posts/{id} | A | Literal segment more specific |
Two patterns conflict if neither is more specific than the other. Registering conflicting patterns causes a panic.
// CONFLICT - will panic
mux.HandleFunc("/posts/{id}", handler1)
mux.HandleFunc("/{resource}/latest", handler2)
// Both match /posts/latest, neither is more specific
Patterns with hosts take precedence over patterns without:
mux.HandleFunc("example.com/", hostHandler) // wins for example.com
mux.HandleFunc("/", defaultHandler) // wins for other hosts
package main
import (
"encoding/json"
"net/http"
)
func main() {
mux := http.NewServeMux()
mux.HandleFunc("GET /api/posts", listPosts)
mux.HandleFunc("GET /api/posts/{id}", getPost)
mux.HandleFunc("POST /api/posts", createPost)
mux.HandleFunc("PUT /api/posts/{id}", updatePost)
mux.HandleFunc("DELETE /api/posts/{id}", deletePost)
mux.HandleFunc("GET /static/{filepath...}", serveStatic)
http.ListenAndServe(":8080", mux)
}
func getPost(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
post, err := findPost(id)
if err != nil {
http.Error(w, "not found", http.StatusNotFound)
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(post)
}
func serveStatic(w http.ResponseWriter, r *http.Request) {
filepath := r.PathValue("filepath")
http.ServeFile(w, r, "static/"+filepath)
}
mux.HandleFunc("GET /api/{resource}", listHandler)
mux.HandleFunc("GET /api/{resource}/{id}", getHandler)
mux.HandleFunc("POST /api/{resource}", createHandler)
mux.HandleFunc("PUT /api/{resource}/{id}", updateHandler)
mux.HandleFunc("DELETE /api/{resource}/{id}", deleteHandler)
mux.HandleFunc("GET /users/{userID}/posts", listUserPosts)
mux.HandleFunc("GET /users/{userID}/posts/{postID}", getUserPost)
mux.HandleFunc("GET /posts/latest", getLatestPost) // more specific
mux.HandleFunc("GET /posts/{id}", getPost) // less specific
For code that relied on pre-1.22 behavior (literal braces in patterns):
GODEBUG=httpmuxgo121=1 ./myapp
/posts/{id} matches all methods{$} - /posts/ matches /posts/anything, use /posts/{$} for exact match{id} and {identifier} are different wildcards, name doesn't affect precedence