-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[docs] Add example usage for Route.HeadersRegexp #320
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the examples, I think they are good. Just a few stylistic changes requested to group things together for clarity. Let me know if the comments don't make sense :)
example_route_test.go
Outdated
req1, _ := http.NewRequest("GET", "example.com", nil) | ||
req2, _ := http.NewRequest("GET", "example.com", nil) | ||
|
||
req1.Header.Add("Accept", "text/plain") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move next to the declaration of req1
example_route_test.go
Outdated
func ExampleRoute_HeadersRegexp() { | ||
r := mux.NewRouter() | ||
route := r.NewRoute().HeadersRegexp("Accept", "html") | ||
matchInfo := &mux.RouteMatch{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to just before the fmt.Printf
, leave a space here to separate the r
and route
from the rest.
example_route_test.go
Outdated
route := r.NewRoute().HeadersRegexp("Accept", "html") | ||
matchInfo := &mux.RouteMatch{} | ||
req1, _ := http.NewRequest("GET", "example.com", nil) | ||
req2, _ := http.NewRequest("GET", "example.com", nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move to just above the req2.Header.Set
...
// for the header value. Using the start and end of string anchors, the | ||
// value must be an exact match. | ||
func ExampleRoute_HeadersRegexp_exactMatch() { | ||
r := mux.NewRouter() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar changes to this function.
Wow, I'm surprised how much more readable that became, thanks. |
Looks great. Thanks a lot! |
Implements the documentation aspect of #124.
Updates the documentation comment header for
route.go:Route.HeadersRegexp
. And also addsexample_route_test.go
containing:ExampleRoute_HeadersRegexp
. Demonstrates the wildcard behavior of Go'sregexp.Compile
.ExampleRoute_HeadersRegexp_exactMatch
. Demonstrates strict matching using start and end of string anchors.