Browse Source

Name change all Url to URL in URLQuery middleware.

Simon Guest 10 years ago
parent
commit
0835e6ab6f
2 changed files with 11 additions and 11 deletions
  1. +5
    -5
      web/middleware/urlquery.go
  2. +6
    -6
      web/middleware/urlquery_test.go

+ 5
- 5
web/middleware/urlquery.go View File

@ -5,17 +5,17 @@ import (
"net/http"
)
// UrlQueryKey is the context key for the URL Query
const UrlQueryKey string = "urlquery"
// URLQueryKey is the context key for the URL Query
const URLQueryKey string = "urlquery"
// UrlQuery is a middleware to parse the URL Query parameters just once,
// URLQuery is a middleware to parse the URL Query parameters just once,
// and store the resulting url.Values in the context.
func UrlQuery(c *web.C, h http.Handler) http.Handler {
func URLQuery(c *web.C, h http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if c.Env == nil {
c.Env = make(map[interface{}]interface{})
}
c.Env[UrlQueryKey] = r.URL.Query()
c.Env[URLQueryKey] = r.URL.Query()
h.ServeHTTP(w, r)
}


+ 6
- 6
web/middleware/urlquery_test.go View File

@ -10,20 +10,20 @@ import (
"github.com/zenazn/goji/web"
)
func testUrlQuery(r *http.Request, f func(*web.C, http.ResponseWriter, *http.Request)) *httptest.ResponseRecorder {
func testURLQuery(r *http.Request, f func(*web.C, http.ResponseWriter, *http.Request)) *httptest.ResponseRecorder {
var c web.C
h := func(w http.ResponseWriter, r *http.Request) {
f(&c, w, r)
}
m := UrlQuery(&c, http.HandlerFunc(h))
m := URLQuery(&c, http.HandlerFunc(h))
w := httptest.NewRecorder()
m.ServeHTTP(w, r)
return w
}
func TestUrlQuery(t *testing.T) {
func TestURLQuery(t *testing.T) {
type testcase struct {
url string
expectedParams url.Values
@ -39,11 +39,11 @@ func TestUrlQuery(t *testing.T) {
for _, tc := range testcases {
r, _ := http.NewRequest("GET", tc.url, nil)
testUrlQuery(r,
testURLQuery(r,
func(c *web.C, w http.ResponseWriter, r *http.Request) {
params := c.Env[UrlQueryKey].(url.Values)
params := c.Env[URLQueryKey].(url.Values)
if !reflect.DeepEqual(params, tc.expectedParams) {
t.Errorf("GET %s, UrlQuery middleware found %v, should be %v", tc.url, params, tc.expectedParams)
t.Errorf("GET %s, URLQuery middleware found %v, should be %v", tc.url, params, tc.expectedParams)
}
w.Write([]byte{'h', 'i'})


Loading…
Cancel
Save