diff options
Diffstat (limited to 'libgo/go/net/http/example_test.go')
-rw-r--r-- | libgo/go/net/http/example_test.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libgo/go/net/http/example_test.go b/libgo/go/net/http/example_test.go index bc60df7..88b97d9 100644 --- a/libgo/go/net/http/example_test.go +++ b/libgo/go/net/http/example_test.go @@ -68,3 +68,21 @@ func ExampleStripPrefix() { // URL's path before the FileServer sees it: http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp")))) } + +type apiHandler struct{} + +func (apiHandler) ServeHTTP(http.ResponseWriter, *http.Request) {} + +func ExampleServeMux_Handle() { + mux := http.NewServeMux() + mux.Handle("/api/", apiHandler{}) + mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + // The "/" pattern matches everything, so we need to check + // that we're at the root here. + if req.URL.Path != "/" { + http.NotFound(w, req) + return + } + fmt.Fprintf(w, "Welcome to the home page!") + }) +} |