mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
Add PostValuesAll, PostValues, PostValue shortcut for aio multipart, form data, raw post, query data
This commit is contained in:
parent
77955c8540
commit
f8f6abd906
61
context.go
61
context.go
|
@ -317,6 +317,67 @@ func (ctx *Context) FormValues(name string) []string {
|
||||||
return arrStr
|
return arrStr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PostValuesAll returns all post data values with their keys
|
||||||
|
// multipart, form data, get & post query arguments
|
||||||
|
func (ctx *Context) PostValuesAll() (valuesAll map[string][]string) {
|
||||||
|
reqCtx := ctx.RequestCtx
|
||||||
|
valuesAll = make(map[string][]string)
|
||||||
|
// first check if we have multipart form
|
||||||
|
multipartForm, err := reqCtx.MultipartForm()
|
||||||
|
if err == nil {
|
||||||
|
//we have multipart form
|
||||||
|
return multipartForm.Value
|
||||||
|
}
|
||||||
|
// if no multipart and post arguments ( means normal form)
|
||||||
|
|
||||||
|
if reqCtx.PostArgs().Len() == 0 && reqCtx.QueryArgs().Len() == 0 {
|
||||||
|
return // no found
|
||||||
|
}
|
||||||
|
|
||||||
|
reqCtx.PostArgs().VisitAll(func(k []byte, v []byte) {
|
||||||
|
key := string(k)
|
||||||
|
value := string(v)
|
||||||
|
// for slices
|
||||||
|
if valuesAll[key] != nil {
|
||||||
|
valuesAll[key] = append(valuesAll[key], value)
|
||||||
|
} else {
|
||||||
|
valuesAll[key] = []string{value}
|
||||||
|
}
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
reqCtx.QueryArgs().VisitAll(func(k []byte, v []byte) {
|
||||||
|
key := string(k)
|
||||||
|
value := string(v)
|
||||||
|
// for slices
|
||||||
|
if valuesAll[key] != nil {
|
||||||
|
valuesAll[key] = append(valuesAll[key], value)
|
||||||
|
} else {
|
||||||
|
valuesAll[key] = []string{value}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostValues returns the post data values as []string of a single key/name
|
||||||
|
func (ctx *Context) PostValues(name string) []string {
|
||||||
|
values := make([]string, 0)
|
||||||
|
if v := ctx.PostValuesAll(); v != nil && len(v) > 0 {
|
||||||
|
values = v[name]
|
||||||
|
}
|
||||||
|
return values
|
||||||
|
}
|
||||||
|
|
||||||
|
// PostValue returns the post data value of a single key/name
|
||||||
|
// returns an empty string if nothing found
|
||||||
|
func (ctx *Context) PostValue(name string) string {
|
||||||
|
if v := ctx.PostValues(name); len(v) > 0 {
|
||||||
|
return v[0]
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
// Subdomain returns the subdomain (string) of this request, if any
|
// Subdomain returns the subdomain (string) of this request, if any
|
||||||
func (ctx *Context) Subdomain() (subdomain string) {
|
func (ctx *Context) Subdomain() (subdomain string) {
|
||||||
host := ctx.HostString()
|
host := ctx.HostString()
|
||||||
|
|
|
@ -43,6 +43,9 @@ type (
|
||||||
RequestHeader(k string) string
|
RequestHeader(k string) string
|
||||||
FormValueString(string) string
|
FormValueString(string) string
|
||||||
FormValues(string) []string
|
FormValues(string) []string
|
||||||
|
PostValuesAll() map[string][]string
|
||||||
|
PostValues(name string) []string
|
||||||
|
PostValue(name string) string
|
||||||
SetStatusCode(int)
|
SetStatusCode(int)
|
||||||
SetContentType(string)
|
SetContentType(string)
|
||||||
SetHeader(string, string)
|
SetHeader(string, string)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user