|
@@ -230,11 +230,27 @@ 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) {
|
|
|
|
|
+ if values, ok := c.GetQueryArray(key); ok {
|
|
|
|
|
+ return values[0], ok
|
|
|
|
|
+ }
|
|
|
|
|
+ return "", false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// QueryArray returns a slice of strings for a given query key.
|
|
|
|
|
+// The length of the slice depends on the number of params with the given key.
|
|
|
|
|
+func (c *Context) QueryArray(key string) []string {
|
|
|
|
|
+ values, _ := c.GetQueryArray(key)
|
|
|
|
|
+ return values
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// GetQueryArray returns a slice of strings for a given query key, plus
|
|
|
|
|
+// a boolean value whether at least one value exists for the given key.
|
|
|
|
|
+func (c *Context) GetQueryArray(key string) ([]string, bool) {
|
|
|
req := c.Request
|
|
req := c.Request
|
|
|
if values, ok := req.URL.Query()[key]; ok && len(values) > 0 {
|
|
if values, ok := req.URL.Query()[key]; ok && len(values) > 0 {
|
|
|
- return values[0], true
|
|
|
|
|
|
|
+ return values, true
|
|
|
}
|
|
}
|
|
|
- return "", false
|
|
|
|
|
|
|
+ return []string{}, false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// PostForm returns the specified key from a POST urlencoded form or multipart form
|
|
// PostForm returns the specified key from a POST urlencoded form or multipart form
|
|
@@ -262,17 +278,34 @@ 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) {
|
|
|
|
|
+ if values, ok := c.GetPostFormArray(key); ok {
|
|
|
|
|
+ return values[0], ok
|
|
|
|
|
+ }
|
|
|
|
|
+ return "", false
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// PostFormArray returns a slice of strings for a given form key.
|
|
|
|
|
+// The length of the slice depends on the number of params with the given key.
|
|
|
|
|
+func (c *Context) PostFormArray(key string) []string {
|
|
|
|
|
+ values, _ := c.GetPostFormArray(key)
|
|
|
|
|
+ return values
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// GetPostFormArray returns a slice of strings for a given form key, plus
|
|
|
|
|
+// a boolean value whether at least one value exists for the given key.
|
|
|
|
|
+func (c *Context) GetPostFormArray(key string) ([]string, bool) {
|
|
|
req := c.Request
|
|
req := c.Request
|
|
|
|
|
+ req.ParseForm()
|
|
|
req.ParseMultipartForm(32 << 20) // 32 MB
|
|
req.ParseMultipartForm(32 << 20) // 32 MB
|
|
|
if values := req.PostForm[key]; len(values) > 0 {
|
|
if values := req.PostForm[key]; len(values) > 0 {
|
|
|
- return values[0], true
|
|
|
|
|
|
|
+ return values, true
|
|
|
}
|
|
}
|
|
|
if req.MultipartForm != nil && req.MultipartForm.File != nil {
|
|
if req.MultipartForm != nil && req.MultipartForm.File != nil {
|
|
|
if values := req.MultipartForm.Value[key]; len(values) > 0 {
|
|
if values := req.MultipartForm.Value[key]; len(values) > 0 {
|
|
|
- return values[0], true
|
|
|
|
|
|
|
+ return values, true
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- return "", false
|
|
|
|
|
|
|
+ return []string{}, false
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Bind checks the Content-Type to select a binding engine automatically,
|
|
// Bind checks the Content-Type to select a binding engine automatically,
|