File: urlquery.go

package info (click to toggle)
golang-github-zenazn-goji 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 464 kB
  • sloc: makefile: 3
file content (24 lines) | stat: -rw-r--r-- 563 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package middleware

import (
	"github.com/zenazn/goji/web"
	"net/http"
)

// 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,
// and store the resulting url.Values in the context.
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()

		h.ServeHTTP(w, r)
	}

	return http.HandlerFunc(fn)
}