1104.

Better HTTP server routing in Go 1.22 - Eli Bendersky's website

eli.thegreenplace.net/2023/better-http-server-routing-in-go-122

The fish told me of this cool new feature. In short,

func main() {
  mux := http.NewServeMux()
  mux.HandleFunc("GET /path/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprint(w, "got path\n")
  })

  mux.HandleFunc("/task/{id}/", func(w http.ResponseWriter, r *http.Request) {
    id := r.PathValue("id")
    fmt.Fprintf(w, "handling task with id=%v\n", id)
  })

  http.ListenAndServe("localhost:8090", mux)
}

Handy!