Browse Source

[docs] Satisfied golint.

- SkipRouter should also be ErrRouterSkipped (or similar) but a change would
  break the public API.
Matt Silverlock 10 years ago
parent
commit
02c98b3f73
5 changed files with 19 additions and 16 deletions
  1. +1
    -1
      doc.go
  2. +1
    -1
      mux.go
  3. +3
    -3
      old_test.go
  4. +10
    -9
      regexp.go
  5. +4
    -2
      route.go

+ 1
- 1
doc.go View File

@ -3,7 +3,7 @@
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
/* /*
Package gorilla/mux implements a request router and dispatcher.
Package mux implements a request router and dispatcher.
The name mux stands for "HTTP request multiplexer". Like the standard The name mux stands for "HTTP request multiplexer". Like the standard
http.ServeMux, mux.Router matches incoming requests against a list of http.ServeMux, mux.Router matches incoming requests against a list of


+ 1
- 1
mux.go View File

@ -236,7 +236,7 @@ func (r *Router) Schemes(schemes ...string) *Route {
return r.NewRoute().Schemes(schemes...) return r.NewRoute().Schemes(schemes...)
} }
// BuildVars registers a new route with a custom function for modifying
// BuildVarsFunc registers a new route with a custom function for modifying
// route variables before building a URL. // route variables before building a URL.
func (r *Router) BuildVarsFunc(f BuildVarsFunc) *Route { func (r *Router) BuildVarsFunc(f BuildVarsFunc) *Route {
return r.NewRoute().BuildVarsFunc(f) return r.NewRoute().BuildVarsFunc(f)


+ 3
- 3
old_test.go View File

@ -576,10 +576,10 @@ func TestSubRouting(t *testing.T) {
} }
u, _ := router.Get("products").URL() u, _ := router.Get("products").URL()
builtUrl := u.String()
builtURL := u.String()
// Yay, subroute aware of the domain when building! // Yay, subroute aware of the domain when building!
if builtUrl != url {
t.Errorf("Expected %q, got %q.", url, builtUrl)
if builtURL != url {
t.Errorf("Expected %q, got %q.", url, builtURL)
} }
} }


+ 10
- 9
regexp.go View File

@ -151,10 +151,11 @@ func (r *routeRegexp) Match(req *http.Request, match *RouteMatch) bool {
if !r.matchHost { if !r.matchHost {
if r.matchQuery { if r.matchQuery {
return r.matchQueryString(req) return r.matchQueryString(req)
} else {
return r.regexp.MatchString(req.URL.Path)
} }
return r.regexp.MatchString(req.URL.Path)
} }
return r.regexp.MatchString(getHost(req)) return r.regexp.MatchString(getHost(req))
} }
@ -184,10 +185,10 @@ func (r *routeRegexp) url(values map[string]string) (string, error) {
return rv, nil return rv, nil
} }
// getUrlQuery returns a single query parameter from a request URL.
// getURLQuery returns a single query parameter from a request URL.
// For a URL with foo=bar&baz=ding, we return only the relevant key // For a URL with foo=bar&baz=ding, we return only the relevant key
// value pair for the routeRegexp. // value pair for the routeRegexp.
func (r *routeRegexp) getUrlQuery(req *http.Request) string {
func (r *routeRegexp) getURLQuery(req *http.Request) string {
if !r.matchQuery { if !r.matchQuery {
return "" return ""
} }
@ -201,14 +202,14 @@ func (r *routeRegexp) getUrlQuery(req *http.Request) string {
} }
func (r *routeRegexp) matchQueryString(req *http.Request) bool { func (r *routeRegexp) matchQueryString(req *http.Request) bool {
return r.regexp.MatchString(r.getUrlQuery(req))
return r.regexp.MatchString(r.getURLQuery(req))
} }
// braceIndices returns the first level curly brace indices from a string. // braceIndices returns the first level curly brace indices from a string.
// It returns an error in case of unbalanced braces. // It returns an error in case of unbalanced braces.
func braceIndices(s string) ([]int, error) { func braceIndices(s string) ([]int, error) {
var level, idx int var level, idx int
idxs := make([]int, 0)
var idxs []int
for i := 0; i < len(s); i++ { for i := 0; i < len(s); i++ {
switch s[i] { switch s[i] {
case '{': case '{':
@ -278,10 +279,10 @@ func (v *routeRegexpGroup) setMatch(req *http.Request, m *RouteMatch, r *Route)
} }
// Store query string variables. // Store query string variables.
for _, q := range v.queries { for _, q := range v.queries {
queryUrl := q.getUrlQuery(req)
matches := q.regexp.FindStringSubmatchIndex(queryUrl)
queryURL := q.getURLQuery(req)
matches := q.regexp.FindStringSubmatchIndex(queryURL)
if len(matches) > 0 { if len(matches) > 0 {
extractVars(queryUrl, matches, q.varsN, m.Vars)
extractVars(queryURL, matches, q.varsN, m.Vars)
} }
} }
} }


+ 4
- 2
route.go View File

@ -217,8 +217,9 @@ func (m headerRegexMatcher) Match(r *http.Request, match *RouteMatch) bool {
return matchMapWithRegex(m, r.Header, true) return matchMapWithRegex(m, r.Header, true)
} }
// Regular expressions can be used with headers as well.
// It accepts a sequence of key/value pairs, where the value has regex support. For example
// HeadersRegexp accepts a sequence of key/value pairs, where the value has regex
// support. For example:
//
// r := mux.NewRouter() // r := mux.NewRouter()
// r.HeadersRegexp("Content-Type", "application/(text|json)", // r.HeadersRegexp("Content-Type", "application/(text|json)",
// "X-Requested-With", "XMLHttpRequest") // "X-Requested-With", "XMLHttpRequest")
@ -263,6 +264,7 @@ func (r *Route) Host(tpl string) *Route {
// MatcherFunc is the function signature used by custom matchers. // MatcherFunc is the function signature used by custom matchers.
type MatcherFunc func(*http.Request, *RouteMatch) bool type MatcherFunc func(*http.Request, *RouteMatch) bool
// Match returns the match for a given request.
func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool { func (m MatcherFunc) Match(r *http.Request, match *RouteMatch) bool {
return m(r, match) return m(r, match)
} }


Loading…
Cancel
Save