1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 03:17:04 +00:00

implement ReadQuery with 'url' struct field tag name strictly, as requested at: #1207

Former-commit-id: dc0c237f62aa6db5a0c1755b2074d8a18dba0d8f
This commit is contained in:
Gerasimos (Makis) Maropoulos
2019-07-24 03:29:42 +03:00
parent 227eda3bcc
commit db0702ca75
8 changed files with 65 additions and 15 deletions

View File

@@ -27,7 +27,7 @@ import (
"github.com/Shopify/goreferrer"
"github.com/fatih/structs"
"github.com/iris-contrib/blackfriday"
formbinder "github.com/iris-contrib/formBinder"
"github.com/iris-contrib/schema"
jsoniter "github.com/json-iterator/go"
"github.com/microcosm-cc/bluemonday"
"gopkg.in/yaml.v2"
@@ -589,10 +589,14 @@ type Context interface {
// ReadForm binds the formObject with the form data
// it supports any kind of type, including custom structs.
// It will return nothing if request data are empty.
// The struct field tag is "form".
//
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go
ReadForm(formObjectPtr interface{}) error
ReadForm(formObject interface{}) error
// ReadQuery binds the "ptr" with the url query string. The struct field tag is "url".
//
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-query/main.go
ReadQuery(ptr interface{}) error
// +------------------------------------------------------------+
// | Body (raw) Writers |
// +------------------------------------------------------------+
@@ -2389,16 +2393,17 @@ func (ctx *context) ReadXML(xmlObject interface{}) error {
return ctx.UnmarshalBody(xmlObject, UnmarshalerFunc(xml.Unmarshal))
}
// IsErrPath can be used at `context#ReadForm`.
// IsErrPath can be used at `context#ReadForm` and `context#ReadQuery`.
// It reports whether the incoming error
// can be ignored when server allows unknown post values to be sent by the client.
//
// A shortcut for the `formbinder#IsErrPath`.
var IsErrPath = formbinder.IsErrPath
// A shortcut for the `schema#IsErrPath`.
var IsErrPath = schema.IsErrPath
// ReadForm binds the formObject with the form data
// it supports any kind of type, including custom structs.
// It will return nothing if request data are empty.
// The struct field tag is "form".
//
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-form/main.go
func (ctx *context) ReadForm(formObject interface{}) error {
@@ -2407,10 +2412,19 @@ func (ctx *context) ReadForm(formObject interface{}) error {
return nil
}
// or dec := formbinder.NewDecoder(&formbinder.DecoderOptions{TagName: "form"})
// somewhere at the app level. I did change the tagName to "form"
// inside its source code, so it's not needed for now.
return formbinder.Decode(values, formObject)
return schema.DecodeForm(values, formObject)
}
// ReadQuery binds the "ptr" with the url query string. The struct field tag is "url".
//
// Example: https://github.com/kataras/iris/blob/master/_examples/http_request/read-query/main.go
func (ctx *context) ReadQuery(ptr interface{}) error {
values := ctx.request.URL.Query()
if len(values) == 0 {
return nil
}
return schema.DecodeQuery(values, ptr)
}
// +------------------------------------------------------------+