beego:query data from Form & params
Showing
2 changed files
with
8 additions
and
8 deletions
| ... | @@ -212,6 +212,9 @@ func (input *BeegoInput) Param(key string) string { | ... | @@ -212,6 +212,9 @@ func (input *BeegoInput) Param(key string) string { |
| 212 | 212 | ||
| 213 | // Query returns input data item string by a given string. | 213 | // Query returns input data item string by a given string. |
| 214 | func (input *BeegoInput) Query(key string) string { | 214 | func (input *BeegoInput) Query(key string) string { |
| 215 | if val := input.Param(key); val != "" { | ||
| 216 | return val | ||
| 217 | } | ||
| 215 | if input.Request.Form == nil { | 218 | if input.Request.Form == nil { |
| 216 | input.Request.ParseForm() | 219 | input.Request.ParseForm() |
| 217 | } | 220 | } | ... | ... |
| ... | @@ -285,10 +285,7 @@ func (c *Controller) ServeXml() { | ... | @@ -285,10 +285,7 @@ func (c *Controller) ServeXml() { |
| 285 | 285 | ||
| 286 | // Input returns the input data map from POST or PUT request body and query string. | 286 | // Input returns the input data map from POST or PUT request body and query string. |
| 287 | func (c *Controller) Input() url.Values { | 287 | func (c *Controller) Input() url.Values { |
| 288 | ct := c.Ctx.Request.Header.Get("Content-Type") | 288 | if c.Ctx.Request.Form == nil { |
| 289 | if strings.Contains(ct, "multipart/form-data") { | ||
| 290 | c.Ctx.Request.ParseMultipartForm(MaxMemory) //64MB | ||
| 291 | } else { | ||
| 292 | c.Ctx.Request.ParseForm() | 289 | c.Ctx.Request.ParseForm() |
| 293 | } | 290 | } |
| 294 | return c.Ctx.Request.Form | 291 | return c.Ctx.Request.Form |
| ... | @@ -301,7 +298,7 @@ func (c *Controller) ParseForm(obj interface{}) error { | ... | @@ -301,7 +298,7 @@ func (c *Controller) ParseForm(obj interface{}) error { |
| 301 | 298 | ||
| 302 | // GetString returns the input value by key string. | 299 | // GetString returns the input value by key string. |
| 303 | func (c *Controller) GetString(key string) string { | 300 | func (c *Controller) GetString(key string) string { |
| 304 | return c.Input().Get(key) | 301 | return c.Ctx.Input.Query(key) |
| 305 | } | 302 | } |
| 306 | 303 | ||
| 307 | // GetStrings returns the input string slice by key string. | 304 | // GetStrings returns the input string slice by key string. |
| ... | @@ -320,17 +317,17 @@ func (c *Controller) GetStrings(key string) []string { | ... | @@ -320,17 +317,17 @@ func (c *Controller) GetStrings(key string) []string { |
| 320 | 317 | ||
| 321 | // GetInt returns input value as int64. | 318 | // GetInt returns input value as int64. |
| 322 | func (c *Controller) GetInt(key string) (int64, error) { | 319 | func (c *Controller) GetInt(key string) (int64, error) { |
| 323 | return strconv.ParseInt(c.Input().Get(key), 10, 64) | 320 | return strconv.ParseInt(c.Ctx.Input.Query(key), 10, 64) |
| 324 | } | 321 | } |
| 325 | 322 | ||
| 326 | // GetBool returns input value as bool. | 323 | // GetBool returns input value as bool. |
| 327 | func (c *Controller) GetBool(key string) (bool, error) { | 324 | func (c *Controller) GetBool(key string) (bool, error) { |
| 328 | return strconv.ParseBool(c.Input().Get(key)) | 325 | return strconv.ParseBool(c.Ctx.Input.Query(key)) |
| 329 | } | 326 | } |
| 330 | 327 | ||
| 331 | // GetFloat returns input value as float64. | 328 | // GetFloat returns input value as float64. |
| 332 | func (c *Controller) GetFloat(key string) (float64, error) { | 329 | func (c *Controller) GetFloat(key string) (float64, error) { |
| 333 | return strconv.ParseFloat(c.Input().Get(key), 64) | 330 | return strconv.ParseFloat(c.Ctx.Input.Query(key), 64) |
| 334 | } | 331 | } |
| 335 | 332 | ||
| 336 | // GetFile returns the file data in file upload field named as key. | 333 | // GetFile returns the file data in file upload field named as key. | ... | ... |
-
Please register or sign in to post a comment