diff options
author | Niall Sheridan <nsheridan@gmail.com> | 2016-08-27 01:32:30 +0100 |
---|---|---|
committer | Niall Sheridan <nsheridan@gmail.com> | 2016-08-27 01:32:30 +0100 |
commit | 921818bca208f0c70e85ec670074cb3905cbbc82 (patch) | |
tree | 4aa67ad2bb2083bd486db3f99680d6d08a2c36b3 /vendor/github.com/gorilla/mux/doc.go | |
parent | 7f1c9358805302344a89c1fed4eab1342931b061 (diff) |
Update dependencies
Diffstat (limited to 'vendor/github.com/gorilla/mux/doc.go')
-rw-r--r-- | vendor/github.com/gorilla/mux/doc.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/vendor/github.com/gorilla/mux/doc.go b/vendor/github.com/gorilla/mux/doc.go index 835f534..291ef5e 100644 --- a/vendor/github.com/gorilla/mux/doc.go +++ b/vendor/github.com/gorilla/mux/doc.go @@ -136,6 +136,31 @@ the inner routes use it as base for their paths: // "/products/{key}/details" s.HandleFunc("/{key}/details", ProductDetailsHandler) +Note that the path provided to PathPrefix() represents a "wildcard": calling +PathPrefix("/static/").Handler(...) means that the handler will be passed any +request that matches "/static/*". This makes it easy to serve static files with mux: + + func main() { + var dir string + + flag.StringVar(&dir, "dir", ".", "the directory to serve files from. Defaults to the current dir") + flag.Parse() + r := mux.NewRouter() + + // This will serve files under http://localhost:8000/static/<filename> + r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", http.FileServer(http.Dir(dir)))) + + srv := &http.Server{ + Handler: r, + Addr: "127.0.0.1:8000", + // Good practice: enforce timeouts for servers you create! + WriteTimeout: 15 * time.Second, + ReadTimeout: 15 * time.Second, + } + + log.Fatal(srv.ListenAndServe()) + } + Now let's see how to build registered URLs. Routes can be named. All routes that define a name can have their URLs built, |