Skip to content
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

Merged
merged 2 commits into from
Dec 4, 2017

Conversation

mtso
Copy link
Contributor

@mtso mtso commented Dec 1, 2017

Implements the documentation aspect of #124.

Updates the documentation comment header for route.go:Route.HeadersRegexp. And also adds example_route_test.go containing:

  1. ExampleRoute_HeadersRegexp. Demonstrates the wildcard behavior of Go's regexp.Compile.
  2. ExampleRoute_HeadersRegexp_exactMatch. Demonstrates strict matching using start and end of string anchors.

Copy link
Contributor

@kisielk kisielk left a 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 :)

req1, _ := http.NewRequest("GET", "example.com", nil)
req2, _ := http.NewRequest("GET", "example.com", nil)

req1.Header.Add("Accept", "text/plain")
Copy link
Contributor

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

func ExampleRoute_HeadersRegexp() {
r := mux.NewRouter()
route := r.NewRoute().HeadersRegexp("Accept", "html")
matchInfo := &mux.RouteMatch{}
Copy link
Contributor

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.

route := r.NewRoute().HeadersRegexp("Accept", "html")
matchInfo := &mux.RouteMatch{}
req1, _ := http.NewRequest("GET", "example.com", nil)
req2, _ := http.NewRequest("GET", "example.com", nil)
Copy link
Contributor

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()
Copy link
Contributor

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.

@mtso
Copy link
Contributor Author

mtso commented Dec 4, 2017

Wow, I'm surprised how much more readable that became, thanks.

@kisielk kisielk merged commit 7904d2e into gorilla:master Dec 4, 2017
@kisielk
Copy link
Contributor

kisielk commented Dec 4, 2017

Looks great. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants