github.com/ghodss/etcd@v0.3.1-0.20140417172404-cc329bfa55cb/http/query_params.go (about) 1 package http 2 3 import ( 4 "net/http" 5 "strings" 6 ) 7 8 func NewLowerQueryParamsHandler(hdlr http.Handler) *LowerQueryParamsHandler { 9 return &LowerQueryParamsHandler{hdlr} 10 } 11 12 type LowerQueryParamsHandler struct { 13 Handler http.Handler 14 } 15 16 func (h *LowerQueryParamsHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { 17 err := req.ParseForm() 18 if err == nil { 19 lowerBoolQueryParams(req) 20 } 21 h.Handler.ServeHTTP(w, req) 22 } 23 24 func lowerBoolQueryParams(req *http.Request) { 25 form := req.Form 26 for key, vals := range form { 27 for i, val := range vals { 28 lowered := strings.ToLower(val) 29 if lowered == "true" || lowered == "false" { 30 req.Form[key][i] = lowered 31 } else { 32 req.Form[key][i] = val 33 } 34 } 35 } 36 }