Refactor GetQuery and GetPostForm

This commit is contained in:
Andrey Nering 2016-03-29 21:54:21 -03:00
parent 9366e33ffc
commit f3ff8f827c

View File

@ -229,9 +229,8 @@ func (c *Context) DefaultQuery(key, defaultValue string) string {
// ("", false) == c.GetQuery("id") // ("", false) == c.GetQuery("id")
// ("", true) == c.GetQuery("lastname") // ("", true) == c.GetQuery("lastname")
func (c *Context) GetQuery(key string) (string, bool) { func (c *Context) GetQuery(key string) (string, bool) {
req := c.Request if values, ok := c.GetQueryArray(key); ok {
if values, ok := req.URL.Query()[key]; ok && len(values) > 0 { return values[0], ok
return values[0], true
} }
return "", false return "", false
} }
@ -278,15 +277,8 @@ func (c *Context) DefaultPostForm(key, defaultValue string) string {
// email= --> ("", true) := GetPostForm("email") // set email to "" // email= --> ("", true) := GetPostForm("email") // set email to ""
// --> ("", false) := GetPostForm("email") // do nothing with email // --> ("", false) := GetPostForm("email") // do nothing with email
func (c *Context) GetPostForm(key string) (string, bool) { func (c *Context) GetPostForm(key string) (string, bool) {
req := c.Request if values, ok := c.GetPostFormArray(key); ok {
req.ParseMultipartForm(32 << 20) // 32 MB return values[0], ok
if values := req.PostForm[key]; len(values) > 0 {
return values[0], true
}
if req.MultipartForm != nil && req.MultipartForm.File != nil {
if values := req.MultipartForm.Value[key]; len(values) > 0 {
return values[0], true
}
} }
return "", false return "", false
} }