http.ServeMux

The request router in Go's net/http package, which matches each request's path, and optionally its method, to the handler registered for it.

In more detail

Create one with http.NewServeMux() and register handlers with HandleFunc, such as mux.HandleFunc("/health", health). Since Go 1.22 patterns can include a method and wildcards, such as GET /items/{id}. Using your own mux keeps routing explicit instead of relying on a global default.

Example

mux := http.NewServeMux()
mux.HandleFunc("/health", health)

Related terms

Taught in

References