Documentation ¶
Overview ¶
Package my4040 provides support for setting customized http 404 handler.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler returns a http.Handler which calls handle404 instead of w.Write to write the response body after a 404 status code was written to w.
Example ¶
package main import ( "fmt" "io" "log" "net/http" "github.com/mkch/burrow/my404" ) func main() { http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("This is foo.")) }) handle404 := func(w io.Writer, r *http.Request) { w.Write([]byte(fmt.Sprintf("404 Gopher is not here: %s", r.URL))) } handler := my404.Handler(http.DefaultServeMux, handle404) log.Fatal(http.ListenAndServe("localhost:8181", handler)) // Please access http://localhost:8181/anything-except-foo in your browser // to get the refined 404 page: // // 404 Gohper is not here: /anything-except-foo }
Output:
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.