Commit Graph

230 Commits

Author SHA1 Message Date
brandon-height
94231ffd98 Fix table-driven example documentation (#363)
Prior to this change, the example documentation
found in the README.md has an errant code which
won't work in the table-driven code example.

This change modifies the variable name from `t` to `tc`
so it does not conflict with the `t *testing.T` struct
definition.

* Adds a range clause to the `for` statement
* Modifies `for` statement scope to use `tc.shouldPass`, and `tc.routeVariable`

Doc: https://github.com/gorilla/mux#testing-handlers
2018-04-03 11:23:30 -07:00
Johan Svensson
4dbd923b0c Make Use() variadic (#355)
Enables neater syntax when chaining several middleware functions.
2018-03-14 09:31:26 -07:00
Geon Kim
07ba1fd60e Modify http status code to variable in README (#350)
* Modify http status code to variable

* Modify doc

* Modify README
2018-02-25 21:11:51 -08:00
Geon Kim
d284fd8421 Modify 403 status code to const variable (#349)
* Modify http status code to variable

* Modify doc
2018-02-25 08:08:54 -08:00
Kamil Kisiel
c0091a0299 Create authentication middleware example. (#340)
* Create authentication middleware example.

For #339

* Fix example test filename.
2018-01-19 23:58:19 -08:00
Franklin Harding
0fdf828bb2 [docs] Clarify SetURLVars (#335)
* [docs] Clarify SetURLVars

Clarify in documentation that SetURLVars does not modify the given
*htttp.Request, provide an example of usage.

* Short and sweet function doc, example test.
2018-01-19 22:28:49 -08:00
Kamil Kisiel
077b44c2cf [docs] Document route.Get* methods consistently (#338)
They actually return an error instead of an empty list. `GetMethods` happened to not return an error, but it should for consistency, so I added that as well.
2018-01-19 20:51:41 -08:00
Kamil Kisiel
dc83507598 [docs] README.md: Improve "walking routes" example. (#337) (#323)
Fixes #323.

Also removed the duplicate "listing routes" example.
2018-01-19 20:47:48 -08:00
safeoy
3dbb9ed96e README.md: add miss "time" (#336) 2018-01-19 20:20:16 -08:00
Matt Silverlock
ad8790881f [docs] Fix doc.go (#333)
Addresses https://github.com/gorilla/mux/pull/294#discussion_r162309666
2018-01-18 09:53:57 -08:00
Matt Silverlock
69dae3b874 [docs] Add testing example (#331) 2018-01-16 23:16:36 -08:00
Matt Silverlock
63c5c2f1f0 [docs] Fix Middleware docs typos (#332) 2018-01-16 23:16:06 -08:00
Kamil Kisiel
85e6bfff1a Update doc.go: r.AddMiddleware(...) -> r.Use(...) 2018-01-16 17:18:53 -08:00
Kush Mansingh
0b74e3d0fe Make shutdown docs compilable (#330) 2018-01-16 14:43:47 -08:00
Roberto Santalla
53c1911da2 [feat] Add middleware support as discussed in #293 (#294)
* mux.Router now has a `Use` method that allows you to add middleware to request processing.
v1.6.1
2018-01-16 09:23:47 -08:00
Matt Silverlock
5bbbb5b2b5 [docs] Add graceful shutdown example (#329) 2018-01-07 07:57:08 -08:00
Kamil Kisiel
512169e5d7 refactor routeRegexp, particularily newRouteRegexp. (#328)
The existing options matchPrefix, matchHost, and matchQueries are
mutually exclusive so there's no point in having a separate boolean
argument for each one. It's clearer if there's a single type variable.

strictSlash and useEncodedPath were also being passed as naked bools so
I've wrapped these in a struct called routeRegexpOptions for more clarity
at the call site.
2018-01-05 10:40:59 -08:00
Zak Chitty
5ab525f4fb Public test API to set URL params (#322)
* Add a function to set url params for test

* [docs] add justification for SetURLVars and description of alternative approach to setting url vars.
* rename SetURLParams to SetURLVars as this is more descriptive.
* rename testing to testing_helpers as this is more descriptive.

* [docs] add stipulation to SetURLVars that it should only be used for testing purposes
2017-12-08 08:08:15 -08:00
Matthew
7904d2e42e [docs] Add example usage for Route.HeadersRegexp (#320)
* Add example usage for Route.HeadersRegexp

* Improve example_route_test.go style
2017-12-04 08:11:14 -08:00
Matt Silverlock
c572efe429 [docs] Note StrictSlash re-direct behaviour #308 (#321)
* [docs] Note StrictSlash re-direct behaviour #308

* StrictSlash enabled routes return a 301 to the client
* As per the HTTP standards, non-idempotent methods, such as POST or PUT, will be followed with a GET by the client
* Users should use middleware if they wish to change this behaviour to return a HTTP 308.

* Update description of StrictSlash
2017-12-02 12:38:52 -08:00
Matt Silverlock
65ec7248c5 Create ISSUE_TEMPLATE.md (#318) 2017-11-28 16:00:09 -08:00
Matthew
4a3d4f3dd2 [bugfix] Fix method subrouter handler matching (#300) (#317)
* Test method-based subrouters for multiple matching paths

* Pass TestMethodsSubrouter

* Change http.Method* constants to string literals
- Make compatible with Go v1.5

* Make TestMethodsSubrouter stateless and concurrent

* Remove t.Run and break up tests for concurrency

* Use backticks to remove quote escaping

* Remove global method handlers and HTTP method constants
2017-11-28 11:51:17 -08:00
Chris Dostert
2d5fef06b8 [docs] fix outdated UseEncodedPath method docs (#314)
https://github.com/gorilla/mux/pull/306 changed UseEncodedPath to use native go encoded path handling so cautions in it's docs are no longer applicable.
2017-11-08 19:54:02 -08:00
Roberto Santalla
7f08801859 MatchErr is set to ErrNotFound if NotFoundHandler is used (#311) v1.6.0 2017-11-05 09:23:20 -08:00
Kamil Kisiel
9f48112f18 [docs] Document router.Match (#313)
* Document router.Match

The return values are getting confusing. Hopefully this helps.

* Simplify some language.

* Remove double the
2017-11-04 21:08:26 -07:00
Matt Silverlock
bc452d92e3 [build] Allow tip failures (#312)
[build] Allow tip failures
2017-11-04 13:51:27 -07:00
Kamil Kisiel
7625a85c14 .travis.yml: Remove versions < go1.5 from build matrix 2017-10-19 20:47:00 -07:00
Mike Busch
c9183aaddd use req.URL.EscapedPath() instead of getPath(req) (#306)
This change drops support of go < 1.5. go1.5 has been officially
unsupported since go1.7 was released 2016/08/15.
2017-10-19 20:46:20 -07:00
Paul B. Beskow
10490f55fa GetQueryTemplates and GetQueryRegexp extraction (#304)
Developers can now extract the query templates and regexps
from a router as lists of combined query pairs.
2017-10-19 18:19:04 -07:00
Adam Ouellette
9bd9ff2d1d Added 1.9 build step (#303) 2017-10-10 14:54:56 -07:00
Pontus Leitzler
bdd5a5a1b0 Fix WriteHeader in TestA301ResponseWriter. (#301)
WriteHeader did only set status field for a local copy that was discared
upon return.
2017-10-08 14:49:13 -07:00
Matthew Riley
3f19343c7d [docs] Document evaluation order for routes (#297) 2017-09-22 13:54:14 -07:00
Stephan Renatus
24fca303ac [docs] README.md: add missing . (#292) v1.5.0 2017-09-05 10:10:44 -07:00
Matt Silverlock
bb285ea687 [docs] Fix missing space in docstring (#289) 2017-08-30 13:57:41 -07:00
Mayank Patel
a659b61323 Fix #271: Return 405 instead of 404 when request method doesn't match the route 2017-08-29 22:39:17 -07:00
Chris Hines
ac112f7d75 Prefer scheme on child route when building URLs. 2017-07-04 00:43:45 -07:00
Chris Hines
37b3a6cace Use scheme from parent router when building URLs. 2017-07-04 00:43:45 -07:00
Cody Oss
8c683ee571 Fix typo 2017-06-21 15:07:33 -07:00
Chris Hines
18fca31550 Add test and fix for escaped query values.
Reproduces and fixes #238.
2017-06-02 12:31:40 -07:00
Chris Hines
c7a138dbc1 Update docs. 2017-06-02 12:31:40 -07:00
Pavel Ivanov
f9aa23a02b Add tests for support for queries in URL reversing. 2017-06-02 12:31:40 -07:00
Pavel Ivanov
9c9af153a1 Add support for queries in URL reversing. 2017-06-02 12:31:40 -07:00
Nick Hudkins
043ee6597c Update Walking Routes Section
Fixed invalid method chaining.
2017-05-23 18:01:04 -07:00
Nick Hudkins
59ce66852b Fix invalid example code
In the "List Routes" example code, `.HandleFunc` was being called on a `*mux.Route` rather than `*mux.Router`. Updated the example code to work :)
2017-05-23 18:01:04 -07:00
Brian Michel
85b8c203a4 Removing half of conflict marker (#268)
Looks like there was just part of a conflict marker in the README file, so I figured I'd remove it.
2017-05-22 19:46:13 -07:00
Nick Miyake
456bcfa82d Update README with example for Router.Walk 2017-05-22 08:17:48 -07:00
Nick Miyake
4d814f7650 Update ancestors parameter for WalkFunc for matcher subrouters
Fixes #263
2017-05-22 08:17:48 -07:00
Nick Miyake
a322b2c2ec Update Walk to match all subrouters
Matches all routes instead of just routes with paths.

Fixes #261
2017-05-21 14:35:07 -07:00
Chris Hines
bcd8bc72b0 Support building URLs with non-http schemes. (#260)
* Move misplaced tests and fix comments.

* Support building URLs with non-http schemes.

- Capture first scheme configured for a route for use when building
  URLs.
- Add new Route.URLScheme method similar to URLHost and URLPath.
- Update Route.URLHost and Route.URL to use the captured scheme if
  present.

* Remove Route.URLScheme method.

* Remove UTF-8 BOM.
v1.4.0
2017-05-20 21:50:13 -07:00
Bulat Gaifullin
751308a60a Updated README 2017-05-20 15:55:46 -07:00