|
|
@ -12,6 +12,7 @@ import (
|
|
|
|
const (
|
|
|
|
const (
|
|
|
|
formKey = "form"
|
|
|
|
formKey = "form"
|
|
|
|
pathKey = "path"
|
|
|
|
pathKey = "path"
|
|
|
|
|
|
|
|
headerKey = "header"
|
|
|
|
emptyJson = "{}"
|
|
|
|
emptyJson = "{}"
|
|
|
|
maxMemory = 32 << 20 // 32MB
|
|
|
|
maxMemory = 32 << 20 // 32MB
|
|
|
|
maxBodyLen = 8 << 20 // 8MB
|
|
|
|
maxBodyLen = 8 << 20 // 8MB
|
|
|
@ -20,8 +21,9 @@ const (
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
var (
|
|
|
|
formUnmarshaler = mapping.NewUnmarshaler(formKey, mapping.WithStringValues())
|
|
|
|
formUnmarshaler = mapping.NewUnmarshaler(formKey, mapping.WithStringValues())
|
|
|
|
pathUnmarshaler = mapping.NewUnmarshaler(pathKey, mapping.WithStringValues())
|
|
|
|
pathUnmarshaler = mapping.NewUnmarshaler(pathKey, mapping.WithStringValues())
|
|
|
|
|
|
|
|
headerUnmarshaler = mapping.NewUnmarshaler(headerKey, mapping.WithStringValues())
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Parse parses the request.
|
|
|
|
// Parse parses the request.
|
|
|
@ -34,9 +36,28 @@ func Parse(r *http.Request, v interface{}) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if err := ParseHeaders(r, v); err != nil {
|
|
|
|
|
|
|
|
return err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return ParseJsonBody(r, v)
|
|
|
|
return ParseJsonBody(r, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ParseHeaders parses the headers request.
|
|
|
|
|
|
|
|
func ParseHeaders(r *http.Request, v interface{}) error {
|
|
|
|
|
|
|
|
m := map[string]interface{}{}
|
|
|
|
|
|
|
|
for k, v := range r.Header {
|
|
|
|
|
|
|
|
k = strings.ToLower(k)
|
|
|
|
|
|
|
|
if len(v) == 1 {
|
|
|
|
|
|
|
|
m[k] = v[0]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m[k] = v
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return headerUnmarshaler.Unmarshal(m, v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ParseForm parses the form request.
|
|
|
|
// ParseForm parses the form request.
|
|
|
|
func ParseForm(r *http.Request, v interface{}) error {
|
|
|
|
func ParseForm(r *http.Request, v interface{}) error {
|
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|
if err := r.ParseForm(); err != nil {
|
|
|
|