Skip to content

Commit 79f2f45

Browse files
andrew-werdnaAndrew Browncoreydaley
authored
Clarify documentation examples of Route methods (#672)
Fixes #666 **Summary of Changes** 1. Update `Route` method documentation comments where the example in the comments showed a `Router` before. Updated method names include: * `Headers` * `HeadersRegexp` * `Host` * `Path` * `Queries` * `Subrouter` * `URL` Notes: * This includes what PR #667 did plus some changes requested by a maintainer in the comments * I was a little torn about changing the example in `Subrouter` since `(*Router).Host()` (like several `(*Router)` methods) just calls `(*Router).NewRoute().Host()` so I understand if maintainers are ambivalent about that example or want it to remain the same. Signed-off-by: Corey Daley <[email protected]> Co-authored-by: Andrew Brown <[email protected]> Co-authored-by: Corey Daley <[email protected]>
1 parent 395ad81 commit 79f2f45

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

route.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ func (m headerMatcher) Match(r *http.Request, match *RouteMatch) bool {
240240
// Headers adds a matcher for request header values.
241241
// It accepts a sequence of key/value pairs to be matched. For example:
242242
//
243-
// r := mux.NewRouter()
243+
// r := mux.NewRouter().NewRoute()
244244
// r.Headers("Content-Type", "application/json",
245245
// "X-Requested-With", "XMLHttpRequest")
246246
//
@@ -265,7 +265,7 @@ func (m headerRegexMatcher) Match(r *http.Request, match *RouteMatch) bool {
265265
// HeadersRegexp accepts a sequence of key/value pairs, where the value has regex
266266
// support. For example:
267267
//
268-
// r := mux.NewRouter()
268+
// r := mux.NewRouter().NewRoute()
269269
// r.HeadersRegexp("Content-Type", "application/(text|json)",
270270
// "X-Requested-With", "XMLHttpRequest")
271271
//
@@ -293,7 +293,7 @@ func (r *Route) HeadersRegexp(pairs ...string) *Route {
293293
//
294294
// For example:
295295
//
296-
// r := mux.NewRouter()
296+
// r := mux.NewRouter().NewRoute()
297297
// r.Host("www.example.com")
298298
// r.Host("{subdomain}.domain.com")
299299
// r.Host("{subdomain:[a-z]+}.domain.com")
@@ -352,7 +352,7 @@ func (r *Route) Methods(methods ...string) *Route {
352352
//
353353
// For example:
354354
//
355-
// r := mux.NewRouter()
355+
// r := mux.NewRouter().NewRoute()
356356
// r.Path("/products/").Handler(ProductsHandler)
357357
// r.Path("/products/{key}").Handler(ProductsHandler)
358358
// r.Path("/articles/{category}/{id:[0-9]+}").
@@ -387,7 +387,7 @@ func (r *Route) PathPrefix(tpl string) *Route {
387387
// It accepts a sequence of key/value pairs. Values may define variables.
388388
// For example:
389389
//
390-
// r := mux.NewRouter()
390+
// r := mux.NewRouter().NewRoute()
391391
// r.Queries("foo", "bar", "id", "{id:[0-9]+}")
392392
//
393393
// The above route will only match if the URL contains the defined queries
@@ -483,7 +483,7 @@ func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
483483
//
484484
// It will test the inner routes only if the parent route matched. For example:
485485
//
486-
// r := mux.NewRouter()
486+
// r := mux.NewRouter().NewRoute()
487487
// s := r.Host("www.example.com").Subrouter()
488488
// s.HandleFunc("/products/", ProductsHandler)
489489
// s.HandleFunc("/products/{key}", ProductHandler)
@@ -534,7 +534,7 @@ func (r *Route) Subrouter() *Router {
534534
// The scheme of the resulting url will be the first argument that was passed to Schemes:
535535
//
536536
// // url.String() will be "https://example.com"
537-
// r := mux.NewRouter()
537+
// r := mux.NewRouter().NewRoute()
538538
// url, err := r.Host("example.com")
539539
// .Schemes("https", "http").URL()
540540
//

0 commit comments

Comments
 (0)