0PricingLogin
Go Academy · Lesson

Routing and Path Parameters

Registering handlers and parsing URL params

Standard mux limitations

The default http.ServeMux does not support path parameters (e.g. /users/{id}) or method-based routing. Go 1.22 added enhanced pattern support.

Go 1.22 enhanced patterns

From Go 1.22, ServeMux supports method prefix and path parameters:

mux.HandleFunc("GET /users/{id}", func(w http.ResponseWriter, r *http.Request) {
    id := r.PathValue("id")
    fmt.Fprintln(w, "user:", id)
})

All lessons in this course

  1. Creating an HTTP Server
  2. Routing and Path Parameters
  3. Middleware Pattern
  4. Graceful Shutdown
← Back to Go Academy