From 1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Mon, 13 Nov 2017 09:09:58 -0800 Subject: Updating server dependancies. (#7816) --- vendor/github.com/gorilla/mux/README.md | 36 +++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'vendor/github.com/gorilla/mux/README.md') diff --git a/vendor/github.com/gorilla/mux/README.md b/vendor/github.com/gorilla/mux/README.md index 8dcd71887..67a79e00a 100644 --- a/vendor/github.com/gorilla/mux/README.md +++ b/vendor/github.com/gorilla/mux/README.md @@ -135,6 +135,14 @@ r.HandleFunc("/products", ProductsHandler). Schemes("http") ``` +Routes are tested in the order they were added to the router. If two routes match, the first one wins: + +```go +r := mux.NewRouter() +r.HandleFunc("/specific", specificHandler) +r.PathPrefix("/").Handler(catchAllHandler) +``` + Setting the same matching conditions again and again can be boring, so we have a way to group several routes that share the same requirements. We call it "subrouting". For example, let's say we have several URLs that should only match when the host is `www.example.com`. Create a route for that host and get a "subrouter" from it: @@ -193,22 +201,34 @@ func main() { r.HandleFunc("/products", handler).Methods("POST") r.HandleFunc("/articles", handler).Methods("GET") r.HandleFunc("/articles/{id}", handler).Methods("GET", "PUT") + r.HandleFunc("/authors", handler).Queries("surname", "{surname}") r.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error { t, err := route.GetPathTemplate() if err != nil { return err } + qt, err := route.GetQueriesTemplates() + if err != nil { + return err + } // p will contain regular expression is compatible with regular expression in Perl, Python, and other languages. // for instance the regular expression for path '/articles/{id}' will be '^/articles/(?P[^/]+)$' p, err := route.GetPathRegexp() if err != nil { return err } + // qr will contain a list of regular expressions with the same semantics as GetPathRegexp, + // just applied to the Queries pairs instead, e.g., 'Queries("surname", "{surname}") will return + // {"^surname=(?P.*)$}. Where each combined query pair will have an entry in the list. + qr, err := route.GetQueriesRegexp() + if err != nil { + return err + } m, err := route.GetMethods() if err != nil { return err } - fmt.Println(strings.Join(m, ","), t, p) + fmt.Println(strings.Join(m, ","), strings.Join(qt, ","), strings.Join(qr, ","), t, p) return nil }) http.Handle("/", r) @@ -331,22 +351,34 @@ r.HandleFunc("/", handler) r.HandleFunc("/products", handler).Methods("POST") r.HandleFunc("/articles", handler).Methods("GET") r.HandleFunc("/articles/{id}", handler).Methods("GET", "PUT") +r.HandleFunc("/authors", handler).Queries("surname", "{surname}") r.Walk(func(route *mux.Route, router *mux.Router, ancestors []*mux.Route) error { t, err := route.GetPathTemplate() if err != nil { return err } + qt, err := route.GetQueriesTemplates() + if err != nil { + return err + } // p will contain a regular expression that is compatible with regular expressions in Perl, Python, and other languages. // For example, the regular expression for path '/articles/{id}' will be '^/articles/(?P[^/]+)$'. p, err := route.GetPathRegexp() if err != nil { return err } + // qr will contain a list of regular expressions with the same semantics as GetPathRegexp, + // just applied to the Queries pairs instead, e.g., 'Queries("surname", "{surname}") will return + // {"^surname=(?P.*)$}. Where each combined query pair will have an entry in the list. + qr, err := route.GetQueriesRegexp() + if err != nil { + return err + } m, err := route.GetMethods() if err != nil { return err } - fmt.Println(strings.Join(m, ","), t, p) + fmt.Println(strings.Join(m, ","), strings.Join(qt, ","), strings.Join(qr, ","), t, p) return nil }) ``` -- cgit v1.2.3-1-g7c22