summaryrefslogtreecommitdiff
path: root/src/pkg/net/http/example_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/pkg/net/http/example_test.go')
-rw-r--r--src/pkg/net/http/example_test.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/pkg/net/http/example_test.go b/src/pkg/net/http/example_test.go
index bc60df7f2..88b97d9e3 100644
--- a/src/pkg/net/http/example_test.go
+++ b/src/pkg/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!")
+ })
+}