Skip to content
Myr

Refactor GetQuery and GetPostForm

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Andrey Nering · committed by Andrey Nering · parent 9366e33 · Browse files · 1 file+4 added−12 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−12 removed

  • other:+4 added−12 removed

1 file+4 added−12 removed

modified:context.go+4 added-12 removed
227 unmodified lines
228// ("Manu", true) == c.GetQuery("name")229// ("", false) == c.GetQuery("id")230// ("", true) == c.GetQuery("lastname")231func (c *Context) GetQuery(key string) (string, bool) {232 req := c.Request233 if values, ok := req.URL.Query()[key]; ok && len(values) > 0 {234 return values[0], true232 if values, ok := c.GetQueryArray(key); ok {233 return values[0], ok234 }235 return "", false236}237
38 unmodified lines
276// email=mail@example.com --> ("mail@example.com", true) := GetPostForm("email") // set email to "mail@example.com"277// email= --> ("", true) := GetPostForm("email") // set email to ""278// --> ("", false) := GetPostForm("email") // do nothing with email279func (c *Context) GetPostForm(key string) (string, bool) {281 req := c.Request282 req.ParseMultipartForm(32 << 20) // 32 MB283 if values := req.PostForm[key]; len(values) > 0 {284 return values[0], true280 if values, ok := c.GetPostFormArray(key); ok {281 return values[0], ok282 }286 if req.MultipartForm != nil && req.MultipartForm.File != nil {287 if values := req.MultipartForm.Value[key]; len(values) > 0 {288 return values[0], true289 }290 }283 return "", false284}285286// PostFormArray returns a slice of strings for a given form key.
309 unmodified lines