dispatch is HTTP request multiplexer compatible with ServeMux of net/http.
- Go 1.7 or lator
No dependency on the third party library.
go get -u github.com/i2bskn/dispatch
package main
import (
"fmt""log""net/http""github.com/i2bskn/dispatch"
)
funchello(w http.ResponseWriter, r*http.Request) {
fmt.Fprintf(w, "Hello %s!", dispatch.Param(r, "name"))
}
funcmain() {
mux:=dispatch.New()
mux.HandleFunc("/hello/:name", hello)
mux.HandleFunc("/", func(w http.ResponseWriter, r*http.Request) {
fmt.Fprint(w, "Home!")
})
log.Fatal(http.ListenAndServe(":8080", mux))
}See also GoDoc.
dispatch is available under the MIT.