]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1] net/http: add example for FileServer to mention StripPrefix
authorShenghou Ma <minux.ma@gmail.com>
Thu, 19 Apr 2012 16:41:10 +0000 (00:41 +0800)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 19 Apr 2012 16:41:10 +0000 (00:41 +0800)
««« backport 362b760ecfc7
net/http: add example for FileServer to mention StripPrefix
        Fixes #3530.

R=golang-dev, rsc, bradfitz
CC=golang-dev
https://golang.org/cl/6032052
»»»

src/pkg/net/http/example_test.go

index 2584afc439ef160c7b3f70213da66fa7c1d1c7d8..ec814407ddb2bddc97cb349b57b003ed60f0cec5 100644 (file)
@@ -49,3 +49,8 @@ func ExampleGet() {
        res.Body.Close()
        fmt.Printf("%s", robots)
 }
+
+func ExampleFileServer() {
+       // we use StripPrefix so that /tmpfiles/somefile will access /tmp/somefile
+       http.Handle("/tmpfiles/", http.StripPrefix("/tmpfiles/", http.FileServer(http.Dir("/tmp"))))
+}