From f3ff8f827ca3cb44aca5db8515d4dd4d530d50af Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Tue, 29 Mar 2016 21:54:21 -0300 Subject: [PATCH] Refactor GetQuery and GetPostForm --- context.go | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/context.go b/context.go index fb4fbde..406afd9 100644 --- a/context.go +++ b/context.go @@ -229,9 +229,8 @@ func (c *Context) DefaultQuery(key, defaultValue string) string { // ("", false) == c.GetQuery("id") // ("", true) == c.GetQuery("lastname") func (c *Context) GetQuery(key string) (string, bool) { - req := c.Request - if values, ok := req.URL.Query()[key]; ok && len(values) > 0 { - return values[0], true + if values, ok := c.GetQueryArray(key); ok { + return values[0], ok } return "", false } @@ -278,15 +277,8 @@ func (c *Context) DefaultPostForm(key, defaultValue string) string { // email= --> ("", true) := GetPostForm("email") // set email to "" // --> ("", false) := GetPostForm("email") // do nothing with email func (c *Context) GetPostForm(key string) (string, bool) { - req := c.Request - req.ParseMultipartForm(32 << 20) // 32 MB - 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 - } + if values, ok := c.GetPostFormArray(key); ok { + return values[0], ok } return "", false }