Documentation
¶
Overview ¶
Package httpmux provides an HTTP request multiplexer with the Go 1.22+ net/http ServeMux pattern syntax.
Normal host Go builds expose ServeMux as an alias of net/http.ServeMux. TinyGo builds and builds using the force_tinygo_logic tag select the compatible implementation in this package. Both variants implement net/http.Handler and expose the same constructor and registration methods.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ServeMux ¶
ServeMux is an alias of net/http.ServeMux in normal host Go builds.
Example ¶
package main
import (
"fmt"
"net/http"
"net/http/httptest"
"github.com/shibukawa/tinygodriver/httpmux"
)
func main() {
mux := httpmux.NewServeMux()
mux.HandleFunc("GET /users/{id}", func(w http.ResponseWriter, r *http.Request) {
_, _ = fmt.Fprint(w, r.PathValue("id"))
})
rr := httptest.NewRecorder()
mux.ServeHTTP(rr, httptest.NewRequest("GET", "/users/42", nil))
fmt.Println(rr.Body.String())
}
Output: 42
Click to show internal directories.
Click to hide internal directories.