[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.
This commit is contained in:
committed by
Kamil Kisiel
parent
077b44c2cf
commit
0fdf828bb2
@@ -2248,6 +2248,15 @@ func TestMethodsSubrouterPathVariable(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ExampleSetURLVars() {
|
||||||
|
req, _ := http.NewRequest("GET", "/foo", nil)
|
||||||
|
req = SetURLVars(req, map[string]string{"foo": "bar"})
|
||||||
|
|
||||||
|
fmt.Println(Vars(req)["foo"])
|
||||||
|
|
||||||
|
// Output: bar
|
||||||
|
}
|
||||||
|
|
||||||
// testMethodsSubrouter runs an individual methodsSubrouterTest.
|
// testMethodsSubrouter runs an individual methodsSubrouterTest.
|
||||||
func testMethodsSubrouter(t *testing.T, test methodsSubrouterTest) {
|
func testMethodsSubrouter(t *testing.T, test methodsSubrouterTest) {
|
||||||
// Execute request
|
// Execute request
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ package mux
|
|||||||
import "net/http"
|
import "net/http"
|
||||||
|
|
||||||
// SetURLVars sets the URL variables for the given request, to be accessed via
|
// SetURLVars sets the URL variables for the given request, to be accessed via
|
||||||
// mux.Vars for testing route behaviour.
|
// mux.Vars for testing route behaviour. Arguments are not modified, a shallow
|
||||||
|
// copy is returned.
|
||||||
//
|
//
|
||||||
// This API should only be used for testing purposes; it provides a way to
|
// This API should only be used for testing purposes; it provides a way to
|
||||||
// inject variables into the request context. Alternatively, URL variables
|
// inject variables into the request context. Alternatively, URL variables
|
||||||
|
|||||||
Reference in New Issue
Block a user