Quote domain names in README.md. Use example.com instead of domain.com
Fixes #119
This commit is contained in:
12
README.md
12
README.md
@@ -60,8 +60,8 @@ Routes can also be restricted to a domain or subdomain. Just define a host
|
|||||||
pattern to be matched. They can also have variables:
|
pattern to be matched. They can also have variables:
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
// Only matches if domain is "www.domain.com".
|
// Only matches if domain is "www.example.com".
|
||||||
r.Host("www.domain.com")
|
r.Host("www.example.com")
|
||||||
// Matches a dynamic subdomain.
|
// Matches a dynamic subdomain.
|
||||||
r.Host("{subdomain:[a-z]+}.domain.com")
|
r.Host("{subdomain:[a-z]+}.domain.com")
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ There are several other matchers that can be added. To match path prefixes:
|
|||||||
...and finally, it is possible to combine several matchers in a single route:
|
...and finally, it is possible to combine several matchers in a single route:
|
||||||
|
|
||||||
r.HandleFunc("/products", ProductsHandler).
|
r.HandleFunc("/products", ProductsHandler).
|
||||||
Host("www.domain.com").
|
Host("www.example.com").
|
||||||
Methods("GET").
|
Methods("GET").
|
||||||
Schemes("http")
|
Schemes("http")
|
||||||
|
|
||||||
@@ -103,11 +103,11 @@ a way to group several routes that share the same requirements.
|
|||||||
We call it "subrouting".
|
We call it "subrouting".
|
||||||
|
|
||||||
For example, let's say we have several URLs that should only match when the
|
For example, let's say we have several URLs that should only match when the
|
||||||
host is "www.domain.com". Create a route for that host and get a "subrouter"
|
host is `www.example.com`. Create a route for that host and get a "subrouter"
|
||||||
from it:
|
from it:
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
s := r.Host("www.domain.com").Subrouter()
|
s := r.Host("www.example.com").Subrouter()
|
||||||
|
|
||||||
Then register routes in the subrouter:
|
Then register routes in the subrouter:
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ Then register routes in the subrouter:
|
|||||||
s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
|
s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
|
||||||
|
|
||||||
The three URL paths we registered above will only be tested if the domain is
|
The three URL paths we registered above will only be tested if the domain is
|
||||||
"www.domain.com", because the subrouter is tested first. This is not
|
`www.example.com`, because the subrouter is tested first. This is not
|
||||||
only convenient, but also optimizes request matching. You can create
|
only convenient, but also optimizes request matching. You can create
|
||||||
subrouters combining any attribute matchers accepted by a route.
|
subrouters combining any attribute matchers accepted by a route.
|
||||||
|
|
||||||
|
|||||||
12
doc.go
12
doc.go
@@ -60,8 +60,8 @@ Routes can also be restricted to a domain or subdomain. Just define a host
|
|||||||
pattern to be matched. They can also have variables:
|
pattern to be matched. They can also have variables:
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
// Only matches if domain is "www.domain.com".
|
// Only matches if domain is "www.example.com".
|
||||||
r.Host("www.domain.com")
|
r.Host("www.example.com")
|
||||||
// Matches a dynamic subdomain.
|
// Matches a dynamic subdomain.
|
||||||
r.Host("{subdomain:[a-z]+}.domain.com")
|
r.Host("{subdomain:[a-z]+}.domain.com")
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ There are several other matchers that can be added. To match path prefixes:
|
|||||||
...and finally, it is possible to combine several matchers in a single route:
|
...and finally, it is possible to combine several matchers in a single route:
|
||||||
|
|
||||||
r.HandleFunc("/products", ProductsHandler).
|
r.HandleFunc("/products", ProductsHandler).
|
||||||
Host("www.domain.com").
|
Host("www.example.com").
|
||||||
Methods("GET").
|
Methods("GET").
|
||||||
Schemes("http")
|
Schemes("http")
|
||||||
|
|
||||||
@@ -103,11 +103,11 @@ a way to group several routes that share the same requirements.
|
|||||||
We call it "subrouting".
|
We call it "subrouting".
|
||||||
|
|
||||||
For example, let's say we have several URLs that should only match when the
|
For example, let's say we have several URLs that should only match when the
|
||||||
host is "www.domain.com". Create a route for that host and get a "subrouter"
|
host is "www.example.com". Create a route for that host and get a "subrouter"
|
||||||
from it:
|
from it:
|
||||||
|
|
||||||
r := mux.NewRouter()
|
r := mux.NewRouter()
|
||||||
s := r.Host("www.domain.com").Subrouter()
|
s := r.Host("www.example.com").Subrouter()
|
||||||
|
|
||||||
Then register routes in the subrouter:
|
Then register routes in the subrouter:
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ Then register routes in the subrouter:
|
|||||||
s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
|
s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
|
||||||
|
|
||||||
The three URL paths we registered above will only be tested if the domain is
|
The three URL paths we registered above will only be tested if the domain is
|
||||||
"www.domain.com", because the subrouter is tested first. This is not
|
"www.example.com", because the subrouter is tested first. This is not
|
||||||
only convenient, but also optimizes request matching. You can create
|
only convenient, but also optimizes request matching. You can create
|
||||||
subrouters combining any attribute matchers accepted by a route.
|
subrouters combining any attribute matchers accepted by a route.
|
||||||
|
|
||||||
|
|||||||
@@ -545,7 +545,7 @@ func TestMatchedRouteName(t *testing.T) {
|
|||||||
router := NewRouter()
|
router := NewRouter()
|
||||||
route := router.NewRoute().Path("/products/").Name(routeName)
|
route := router.NewRoute().Path("/products/").Name(routeName)
|
||||||
|
|
||||||
url := "http://www.domain.com/products/"
|
url := "http://www.example.com/products/"
|
||||||
request, _ := http.NewRequest("GET", url, nil)
|
request, _ := http.NewRequest("GET", url, nil)
|
||||||
var rv RouteMatch
|
var rv RouteMatch
|
||||||
ok := router.Match(request, &rv)
|
ok := router.Match(request, &rv)
|
||||||
@@ -563,10 +563,10 @@ func TestMatchedRouteName(t *testing.T) {
|
|||||||
func TestSubRouting(t *testing.T) {
|
func TestSubRouting(t *testing.T) {
|
||||||
// Example from docs.
|
// Example from docs.
|
||||||
router := NewRouter()
|
router := NewRouter()
|
||||||
subrouter := router.NewRoute().Host("www.domain.com").Subrouter()
|
subrouter := router.NewRoute().Host("www.example.com").Subrouter()
|
||||||
route := subrouter.NewRoute().Path("/products/").Name("products")
|
route := subrouter.NewRoute().Path("/products/").Name("products")
|
||||||
|
|
||||||
url := "http://www.domain.com/products/"
|
url := "http://www.example.com/products/"
|
||||||
request, _ := http.NewRequest("GET", url, nil)
|
request, _ := http.NewRequest("GET", url, nil)
|
||||||
var rv RouteMatch
|
var rv RouteMatch
|
||||||
ok := router.Match(request, &rv)
|
ok := router.Match(request, &rv)
|
||||||
|
|||||||
4
route.go
4
route.go
@@ -255,7 +255,7 @@ func (r *Route) HeadersRegexp(pairs ...string) *Route {
|
|||||||
// For example:
|
// For example:
|
||||||
//
|
//
|
||||||
// r := mux.NewRouter()
|
// r := mux.NewRouter()
|
||||||
// r.Host("www.domain.com")
|
// r.Host("www.example.com")
|
||||||
// r.Host("{subdomain}.domain.com")
|
// r.Host("{subdomain}.domain.com")
|
||||||
// r.Host("{subdomain:[a-z]+}.domain.com")
|
// r.Host("{subdomain:[a-z]+}.domain.com")
|
||||||
//
|
//
|
||||||
@@ -414,7 +414,7 @@ func (r *Route) BuildVarsFunc(f BuildVarsFunc) *Route {
|
|||||||
// It will test the inner routes only if the parent route matched. For example:
|
// It will test the inner routes only if the parent route matched. For example:
|
||||||
//
|
//
|
||||||
// r := mux.NewRouter()
|
// r := mux.NewRouter()
|
||||||
// s := r.Host("www.domain.com").Subrouter()
|
// s := r.Host("www.example.com").Subrouter()
|
||||||
// s.HandleFunc("/products/", ProductsHandler)
|
// s.HandleFunc("/products/", ProductsHandler)
|
||||||
// s.HandleFunc("/products/{key}", ProductHandler)
|
// s.HandleFunc("/products/{key}", ProductHandler)
|
||||||
// s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
|
// s.HandleFunc("/articles/{category}/{id:[0-9]+}"), ArticleHandler)
|
||||||
|
|||||||
Reference in New Issue
Block a user