Skip to content

Commit 4a37f3d

Browse files
committed
Doc: Fixed typos
- Fixed typos Signed-off-by: Tanryberdi <tanryberdi@gmail.com>
1 parent 78c6514 commit 4a37f3d

File tree

6 files changed

+78
-79
lines changed

6 files changed

+78
-79
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ their respective handler.
1717

1818
The name mux stands for "HTTP request multiplexer". Like the standard `http.ServeMux`, `mux.Router` matches incoming requests against a list of registered routes and calls a handler for the route that matches the URL or other conditions. The main features are:
1919

20-
* It implements the `http.Handler` interface so it is compatible with the standard `http.ServeMux`.
20+
* It implements the `http.Handler` interface so, it is compatible with the standard `http.ServeMux`.
2121
* Requests can be matched based on URL host, path, path prefix, schemes, header and query values, HTTP methods or using custom matchers.
2222
* URL hosts, paths and query values can have variables with an optional regular expression.
23-
* Registered URLs can be built, or "reversed", which helps maintaining references to resources.
23+
* Registered URLs can be built, or "reversed", which helps to maintain references to resources.
2424
* Routes can be used as subrouters: nested routes are only tested if the parent route matches. This is useful to define groups of routes that share common conditions like a host, a path prefix or other repeated attributes. As a bonus, this optimizes request matching.
2525

2626
---
@@ -307,7 +307,7 @@ func main() {
307307

308308
Now let's see how to build registered URLs.
309309

310-
Routes can be named. All routes that define a name can have their URLs built, or "reversed". We define a name calling `Name()` on a route. For example:
310+
Routes can be named. All routes that define a name can have their URLs built, or "reversed". We define a name-calling `Name()` on a route. For example:
311311

312312
```go
313313
r := mux.NewRouter()
@@ -381,8 +381,8 @@ url, err := r.Get("article").URL("subdomain", "news",
381381

382382
### Walking Routes
383383

384-
The `Walk` function on `mux.Router` can be used to visit all of the routes that are registered on a router. For example,
385-
the following prints all of the registered routes:
384+
The `Walk` function on `mux.Router` can be used to visit all the routes that are registered on a router. For example,
385+
the following prints all the registered routes:
386386

387387
```go
388388
package main
@@ -515,7 +515,7 @@ Mux middlewares are defined using the de facto standard type:
515515
type MiddlewareFunc func(http.Handler) http.Handler
516516
```
517517

518-
Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed to it, and then calls the handler passed as parameter to the MiddlewareFunc. This takes advantage of closures being able access variables from the context where they are created, while retaining the signature enforced by the receivers.
518+
Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed to it, and then calls the handler passed as parameter to the MiddlewareFunc. This takes advantage of closures being able to access variables from the context where they are created, while retaining the signature enforced by the receivers.
519519

520520
A very basic middleware which logs the URI of the request being handled could be written as:
521521

@@ -623,7 +623,7 @@ func fooHandler(w http.ResponseWriter, r *http.Request) {
623623
}
624624
```
625625

626-
And an request to `/foo` using something like:
626+
And a request to `/foo` using something like:
627627

628628
```bash
629629
curl localhost:8080/foo -v

doc.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ http.ServeMux, mux.Router matches incoming requests against a list of
1010
registered routes and calls a handler for the route that matches the URL
1111
or other conditions. The main features are:
1212
13-
* Requests can be matched based on URL host, path, path prefix, schemes,
14-
header and query values, HTTP methods or using custom matchers.
15-
* URL hosts, paths and query values can have variables with an optional
16-
regular expression.
17-
* Registered URLs can be built, or "reversed", which helps maintaining
18-
references to resources.
19-
* Routes can be used as subrouters: nested routes are only tested if the
20-
parent route matches. This is useful to define groups of routes that
21-
share common conditions like a host, a path prefix or other repeated
22-
attributes. As a bonus, this optimizes request matching.
23-
* It implements the http.Handler interface so it is compatible with the
24-
standard http.ServeMux.
13+
- Requests can be matched based on URL host, path, path prefix, schemes,
14+
header and query values, HTTP methods or using custom matchers.
15+
- URL hosts, paths and query values can have variables with an optional
16+
regular expression.
17+
- Registered URLs can be built, or "reversed", which helps to maintaining
18+
references to resources.
19+
- Routes can be used as subrouters: nested routes are only tested if the
20+
parent route matches. This is useful to define groups of routes that
21+
share common conditions like a host, a path prefix or other repeated
22+
attributes. As a bonus, this optimizes request matching.
23+
- It implements the http.Handler interface, so it is compatible with the
24+
standard http.ServeMux.
2525
2626
Let's start registering a couple of URL paths and handlers:
2727
@@ -173,7 +173,7 @@ request that matches "/static/*". This makes it easy to serve static files with
173173
Now let's see how to build registered URLs.
174174
175175
Routes can be named. All routes that define a name can have their URLs built,
176-
or "reversed". We define a name calling Name() on a route. For example:
176+
or "reversed". We define a name-calling Name() on a route. For example:
177177
178178
r := mux.NewRouter()
179179
r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
@@ -184,7 +184,7 @@ key/value pairs for the route variables. For the previous route, we would do:
184184
185185
url, err := r.Get("article").URL("category", "technology", "id", "42")
186186
187-
...and the result will be a url.URL with the following path:
187+
...and the result will be an url.URL with the following path:
188188
189189
"/articles/technology/42"
190190
@@ -212,7 +212,7 @@ Regex support also exists for matching Headers within a route. For example, we c
212212
213213
r.HeadersRegexp("Content-Type", "application/(text|json)")
214214
215-
...and the route will match both requests with a Content-Type of `application/json` as well as
215+
...and the route will match both requests with a Content-Type of `application/json` and
216216
`application/text`
217217
218218
There's also a way to build only the URL host or path for a route:
@@ -301,6 +301,5 @@ A more complex authentication middleware, which maps session token to users, cou
301301
r.Use(amw.Middleware)
302302
303303
Note: The handler chain will be stopped if your middleware doesn't call `next.ServeHTTP()` with the corresponding parameters. This can be used to abort a request if the middleware writer wants to.
304-
305304
*/
306305
package mux

middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"strings"
66
)
77

8-
// MiddlewareFunc is a function which receives an http.Handler and returns another http.Handler.
8+
// MiddlewareFunc is a function which receives a http.Handler and returns another http.Handler.
99
// Typically, the returned handler is a closure which does something with the http.ResponseWriter and http.Request passed
1010
// to it, and then calls the handler passed as parameter to the MiddlewareFunc.
1111
type MiddlewareFunc func(http.Handler) http.Handler

mux.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ func NewRouter() *Router {
3131
// It implements the http.Handler interface, so it can be registered to serve
3232
// requests:
3333
//
34-
// var router = mux.NewRouter()
34+
// var router = mux.NewRouter()
3535
//
36-
// func main() {
37-
// http.Handle("/", router)
38-
// }
36+
// func main() {
37+
// http.Handle("/", router)
38+
// }
3939
//
40-
// Or, for Google App Engine, register it in a init() function:
40+
// Or, for Google App Engine, register it in an init() function:
4141
//
42-
// func init() {
43-
// http.Handle("/", router)
44-
// }
42+
// func init() {
43+
// http.Handle("/", router)
44+
// }
4545
//
4646
// This will send all incoming requests to the router.
4747
type Router struct {
@@ -127,7 +127,7 @@ func copyRouteRegexp(r *routeRegexp) *routeRegexp {
127127
// Match attempts to match the given request against the router's registered routes.
128128
//
129129
// If the request matches a route of this router or one of its subrouters the Route,
130-
// Handler, and Vars fields of the the match argument are filled and this function
130+
// Handler, and Vars fields of the match argument are filled and this function
131131
// returns true.
132132
//
133133
// If the request does not match any of this router's or its subrouters' routes
@@ -233,7 +233,7 @@ func (r *Router) GetRoute(name string) *Route {
233233
// When false, if the route path is "/path", accessing "/path/" will not match
234234
// this route and vice versa.
235235
//
236-
// The re-direct is a HTTP 301 (Moved Permanently). Note that when this is set for
236+
// The re-direct is an HTTP 301 (Moved Permanently). Note that when this is set for
237237
// routes with a non-idempotent method (e.g. POST, PUT), the subsequent re-directed
238238
// request will be made as a GET by most clients. Use middleware or client settings
239239
// to modify this behaviour as needed.
@@ -364,7 +364,7 @@ func (r *Router) Walk(walkFn WalkFunc) error {
364364
}
365365

366366
// SkipRouter is used as a return value from WalkFuncs to indicate that the
367-
// router that walk is about to descend down to should be skipped.
367+
// router that walk is about to descend to should be skipped.
368368
var SkipRouter = errors.New("skip this router")
369369

370370
// WalkFunc is the type of the function called for each route visited by Walk.
@@ -554,7 +554,7 @@ func matchMapWithString(toCheck map[string]string, toMatch map[string][]string,
554554
return false
555555
} else if v != "" {
556556
// If value was defined as an empty string we only check that the
557-
// key exists. Otherwise we also check for equality.
557+
// key exists. Otherwise, we also check for equality.
558558
valueExists := false
559559
for _, value := range values {
560560
if v == value {
@@ -582,7 +582,7 @@ func matchMapWithRegex(toCheck map[string]*regexp.Regexp, toMatch map[string][]s
582582
return false
583583
} else if v != nil {
584584
// If value was defined as an empty string we only check that the
585-
// key exists. Otherwise we also check for equality.
585+
// key exists. Otherwise, we also check for equality.
586586
valueExists := false
587587
for _, value := range values {
588588
if v.MatchString(value) {

mux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2089,7 +2089,7 @@ func TestErrMatchNotFound(t *testing.T) {
20892089
t.Errorf("Expected ErrNotFound MatchErr, but was %v", match.MatchErr)
20902090
}
20912091

2092-
// Now lets add a 404 handler to subrouter
2092+
// Now let's add a 404 handler to subrouter
20932093
s.NotFoundHandler = http.NotFoundHandler()
20942094
req, _ = http.NewRequest("GET", "/sub/whatever", nil)
20952095

route.go

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,9 @@ func (m headerMatcher) Match(r *http.Request, match *RouteMatch) bool {
230230
// Headers adds a matcher for request header values.
231231
// It accepts a sequence of key/value pairs to be matched. For example:
232232
//
233-
// r := mux.NewRouter()
234-
// r.Headers("Content-Type", "application/json",
235-
// "X-Requested-With", "XMLHttpRequest")
233+
// r := mux.NewRouter()
234+
// r.Headers("Content-Type", "application/json",
235+
// "X-Requested-With", "XMLHttpRequest")
236236
//
237237
// The above route will only match if both request header values match.
238238
// If the value is an empty string, it will match any value if the key is set.
@@ -255,9 +255,9 @@ func (m headerRegexMatcher) Match(r *http.Request, match *RouteMatch) bool {
255255
// HeadersRegexp accepts a sequence of key/value pairs, where the value has regex
256256
// support. For example:
257257
//
258-
// r := mux.NewRouter()
259-
// r.HeadersRegexp("Content-Type", "application/(text|json)",
260-
// "X-Requested-With", "XMLHttpRequest")
258+
// r := mux.NewRouter()
259+
// r.HeadersRegexp("Content-Type", "application/(text|json)",
260+
// "X-Requested-With", "XMLHttpRequest")
261261
//
262262
// The above route will only match if both the request header matches both regular expressions.
263263
// If the value is an empty string, it will match any value if the key is set.
@@ -283,10 +283,10 @@ func (r *Route) HeadersRegexp(pairs ...string) *Route {
283283
//
284284
// For example:
285285
//
286-
// r := mux.NewRouter()
287-
// r.Host("www.example.com")
288-
// r.Host("{subdomain}.domain.com")
289-
// r.Host("{subdomain:[a-z]+}.domain.com")
286+
// r := mux.NewRouter()
287+
// r.Host("www.example.com")
288+
// r.Host("{subdomain}.domain.com")
289+
// r.Host("{subdomain:[a-z]+}.domain.com")
290290
//
291291
// Variable names must be unique in a given route. They can be retrieved
292292
// calling mux.Vars(request).
@@ -342,11 +342,11 @@ func (r *Route) Methods(methods ...string) *Route {
342342
//
343343
// For example:
344344
//
345-
// r := mux.NewRouter()
346-
// r.Path("/products/").Handler(ProductsHandler)
347-
// r.Path("/products/{key}").Handler(ProductsHandler)
348-
// r.Path("/articles/{category}/{id:[0-9]+}").
349-
// Handler(ArticleHandler)
345+
// r := mux.NewRouter()
346+
// r.Path("/products/").Handler(ProductsHandler)
347+
// r.Path("/products/{key}").Handler(ProductsHandler)
348+
// r.Path("/articles/{category}/{id:[0-9]+}").
349+
// Handler(ArticleHandler)
350350
//
351351
// Variable names must be unique in a given route. They can be retrieved
352352
// calling mux.Vars(request).
@@ -377,8 +377,8 @@ func (r *Route) PathPrefix(tpl string) *Route {
377377
// It accepts a sequence of key/value pairs. Values may define variables.
378378
// For example:
379379
//
380-
// r := mux.NewRouter()
381-
// r.Queries("foo", "bar", "id", "{id:[0-9]+}")
380+
// r := mux.NewRouter()
381+
// r.Queries("foo", "bar", "id", "{id:[0-9]+}")
382382
//
383383
// The above route will only match if the URL contains the defined queries
384384
// values, e.g.: ?foo=bar&id=42.
@@ -416,7 +416,7 @@ func (m schemeMatcher) Match(r *http.Request, match *RouteMatch) bool {
416416
// https://golang.org/pkg/net/http/#Request
417417
// "For [most] server requests, fields other than Path and RawQuery will be
418418
// empty."
419-
// Since we're an http muxer, the scheme is either going to be http or https
419+
// Since we're a http muxer, the scheme is either going to be http or https
420420
// though, so we can just set it based on the tls termination state.
421421
if scheme == "" {
422422
if r.TLS == nil {
@@ -473,11 +473,11 @@ func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
473473
//
474474
// It will test the inner routes only if the parent route matched. For example:
475475
//
476-
// r := mux.NewRouter()
477-
// s := r.Host("www.example.com").Subrouter()
478-
// s.HandleFunc("/products/", ProductsHandler)
479-
// s.HandleFunc("/products/{key}", ProductHandler)
480-
// s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
476+
// r := mux.NewRouter()
477+
// s := r.Host("www.example.com").Subrouter()
478+
// s.HandleFunc("/products/", ProductsHandler)
479+
// s.HandleFunc("/products/{key}", ProductHandler)
480+
// s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
481481
//
482482
// Here, the routes registered in the subrouter won't be tested if the host
483483
// doesn't match.
@@ -497,36 +497,36 @@ func (r *Route) Subrouter() *Router {
497497
// It accepts a sequence of key/value pairs for the route variables. For
498498
// example, given this route:
499499
//
500-
// r := mux.NewRouter()
501-
// r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
502-
// Name("article")
500+
// r := mux.NewRouter()
501+
// r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
502+
// Name("article")
503503
//
504504
// ...a URL for it can be built using:
505505
//
506-
// url, err := r.Get("article").URL("category", "technology", "id", "42")
506+
// url, err := r.Get("article").URL("category", "technology", "id", "42")
507507
//
508508
// ...which will return an url.URL with the following path:
509509
//
510-
// "/articles/technology/42"
510+
// "/articles/technology/42"
511511
//
512512
// This also works for host variables:
513513
//
514-
// r := mux.NewRouter()
515-
// r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
516-
// Host("{subdomain}.domain.com").
517-
// Name("article")
514+
// r := mux.NewRouter()
515+
// r.HandleFunc("/articles/{category}/{id:[0-9]+}", ArticleHandler).
516+
// Host("{subdomain}.domain.com").
517+
// Name("article")
518518
//
519-
// // url.String() will be "http://news.domain.com/articles/technology/42"
520-
// url, err := r.Get("article").URL("subdomain", "news",
521-
// "category", "technology",
522-
// "id", "42")
519+
// // url.String() will be "http://news.domain.com/articles/technology/42"
520+
// url, err := r.Get("article").URL("subdomain", "news",
521+
// "category", "technology",
522+
// "id", "42")
523523
//
524524
// The scheme of the resulting url will be the first argument that was passed to Schemes:
525525
//
526-
// // url.String() will be "https://example.com"
527-
// r := mux.NewRouter()
528-
// url, err := r.Host("example.com")
529-
// .Schemes("https", "http").URL()
526+
// // url.String() will be "https://example.com"
527+
// r := mux.NewRouter()
528+
// url, err := r.Host("example.com")
529+
// .Schemes("https", "http").URL()
530530
//
531531
// All variables defined in the route are required, and their values must
532532
// conform to the corresponding patterns.
@@ -697,7 +697,7 @@ func (r *Route) GetMethods() ([]string, error) {
697697
}
698698
for _, m := range r.matchers {
699699
if methods, ok := m.(methodMatcher); ok {
700-
return []string(methods), nil
700+
return methods, nil
701701
}
702702
}
703703
return nil, errors.New("mux: route doesn't have methods")

0 commit comments

Comments
 (0)