Improve docs about leading and trailing slashes
This commit is contained in:
@@ -214,6 +214,15 @@ func TestPathPrefix(t *testing.T) {
|
|||||||
path: "/111",
|
path: "/111",
|
||||||
shouldMatch: true,
|
shouldMatch: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
title: "PathPrefix route, match substring",
|
||||||
|
route: new(Route).PathPrefix("/1"),
|
||||||
|
request: newRequest("GET", "http://localhost/111/222/333"),
|
||||||
|
vars: map[string]string{},
|
||||||
|
host: "",
|
||||||
|
path: "/1",
|
||||||
|
shouldMatch: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
title: "PathPrefix route, URL prefix in request does not match",
|
title: "PathPrefix route, URL prefix in request does not match",
|
||||||
route: new(Route).PathPrefix("/111"),
|
route: new(Route).PathPrefix("/111"),
|
||||||
|
|||||||
8
route.go
8
route.go
@@ -259,7 +259,8 @@ func (r *Route) Methods(methods ...string) *Route {
|
|||||||
// Path -----------------------------------------------------------------------
|
// Path -----------------------------------------------------------------------
|
||||||
|
|
||||||
// Path adds a matcher for the URL path.
|
// Path adds a matcher for the URL path.
|
||||||
// It accepts a template with zero or more URL variables enclosed by {}.
|
// It accepts a template with zero or more URL variables enclosed by {}. The
|
||||||
|
// template must start with a "/".
|
||||||
// Variables can define an optional regexp pattern to me matched:
|
// Variables can define an optional regexp pattern to me matched:
|
||||||
//
|
//
|
||||||
// - {name} matches anything until the next slash.
|
// - {name} matches anything until the next slash.
|
||||||
@@ -283,7 +284,10 @@ func (r *Route) Path(tpl string) *Route {
|
|||||||
|
|
||||||
// PathPrefix -----------------------------------------------------------------
|
// PathPrefix -----------------------------------------------------------------
|
||||||
|
|
||||||
// PathPrefix adds a matcher for the URL path prefix.
|
// PathPrefix adds a matcher for the URL path prefix. Note that it does not
|
||||||
|
// treat slashes specially ("/foobar/" will be matched by the prefix "/foo") so
|
||||||
|
// in most cases you'll want to use a trailing slash here. See Route.Path() for
|
||||||
|
// details on the tpl argument.
|
||||||
func (r *Route) PathPrefix(tpl string) *Route {
|
func (r *Route) PathPrefix(tpl string) *Route {
|
||||||
r.strictSlash = false
|
r.strictSlash = false
|
||||||
r.err = r.addRegexpMatcher(tpl, false, true)
|
r.err = r.addRegexpMatcher(tpl, false, true)
|
||||||
|
|||||||
Reference in New Issue
Block a user