Params
package revel
type Params struct {
url.Values
Fixed url.Values
Route url.Values
Query url.Values
Form url.Values
Files map[string][]*multipart.FileHeader
}
func ParseParams(params *Params, req *Request) {
params.Query = req.URL.Query()
switch req.ContentType {
case "application/x-www-form-urlencoded":
if err := req.ParseForm(); err != nil {
WARN.Println("Error parsing request body:", err)
} else {
params.Form = req.Form
}
case "multipart/form-data":
if err := req.ParseMultipartForm(32 << 20 ); err != nil {
WARN.Println("Error parsing request body:", err)
} else {
params.Form = req.MultipartForm.Value
params.Files = req.MultipartForm.File
}
}
params.Values = params.calcValues()
}
func (p *Params) Bind(dest interface{}, name string) {
value := reflect.ValueOf(dest)
if value.Kind() != reflect.Ptr {
panic("revel/params: non-pointer passed to Bind: " + name)
}
value = value.Elem()
if !value.CanSet() {
panic("revel/params: non-settable variable passed to Bind: " + name)
}
value.Set(Bind(p, name, value.Type()))
}
func ParamsFilter(c *Controller, fc []Filter) {
ParseParams(c.Params, c.Request)
defer func() {
if c.Request.MultipartForm != nil {
err := c.Request.MultipartForm.RemoveAll()
if err != nil {
WARN.Println("Error removing temporary files:", err)
}
}
for _, tmpFile := range c.Params.tmpFiles {
err := os.Remove(tmpFile.Name())
if err != nil {
WARN.Println("Could not remove upload temp file:", err)
}
}
}()
fc[0](c, fc[1:])
}