From db0702ca753ed1a7b6b4c308b1d7c78f4edff543 Mon Sep 17 00:00:00 2001
From: "Gerasimos (Makis) Maropoulos" <kataras2006@hotmail.com>
Date: Wed, 24 Jul 2019 03:29:42 +0300
Subject: [PATCH] implement ReadQuery with 'url' struct field tag name
 strictly, as requested at: #1207

Former-commit-id: dc0c237f62aa6db5a0c1755b2074d8a18dba0d8f
---
 HISTORY.md                                |  5 ++++
 _examples/README.md                       |  1 +
 _examples/README_ZH.md                    |  1 +
 _examples/http_request/read-query/main.go | 29 +++++++++++++++++++
 context/context.go                        | 34 ++++++++++++++++-------
 doc.go                                    |  4 +--
 go.mod                                    |  2 +-
 go.sum                                    |  4 +--
 8 files changed, 65 insertions(+), 15 deletions(-)
 create mode 100644 _examples/http_request/read-query/main.go

diff --git a/HISTORY.md b/HISTORY.md
index c8b9a77a..55394b15 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -21,6 +21,11 @@ Developers are not forced to upgrade if they don't really need it. Upgrade whene
 
 **How to upgrade**: Open your command-line and execute this command: `go get github.com/kataras/iris@v11.2.0`.
 
+# We, 24 July 2019 | v11.2.1
+
+- https://github.com/kataras/iris/issues/1298
+- https://github.com/kataras/iris/issues/1207
+
 # Tu, 23 July 2019 | v11.2.0
 
 Read about the new release at: https://dev.to/kataras/iris-version-11-2-released-22bc
diff --git a/_examples/README.md b/_examples/README.md
index fb61a515..c6d2172c 100644
--- a/_examples/README.md
+++ b/_examples/README.md
@@ -225,6 +225,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [her
     * [Struct Validation](http_request/read-json-struct-validation/main.go)
 - [Read XML](http_request/read-xml/main.go)
 - [Read Form](http_request/read-form/main.go)
+- [Read Query](http_request/read-query/main.go) **NEW**
 - [Read Custom per type](http_request/read-custom-per-type/main.go)
 - [Read Custom via Unmarshaler](http_request/read-custom-via-unmarshaler/main.go)
 - [Read Many times](http_request/read-many/main.go)
diff --git a/_examples/README_ZH.md b/_examples/README_ZH.md
index 13724409..ad0ac9dd 100644
--- a/_examples/README_ZH.md
+++ b/_examples/README_ZH.md
@@ -331,6 +331,7 @@ You can serve [quicktemplate](https://github.com/valyala/quicktemplate) and [her
 - [读取JSON](http_request/read-json/main.go)
 - [读取XML](http_request/read-xml/main.go)
 - [读取Form](http_request/read-form/main.go)
+- [读取Query](http_request/read-query/main.go) **更新**
 - [读取每个类型的自定义结果Custom per type](http_request/read-custom-per-type/main.go)
 - [通过Unmarshaler读取Custom](http_request/read-custom-via-unmarshaler/main.go)
 - [上传/读取文件Upload/Read File](http_request/upload-file/main.go)
diff --git a/_examples/http_request/read-query/main.go b/_examples/http_request/read-query/main.go
new file mode 100644
index 00000000..a3ce1019
--- /dev/null
+++ b/_examples/http_request/read-query/main.go
@@ -0,0 +1,29 @@
+// package main contains an example on how to use the ReadForm, but with the same way you can do the ReadJSON & ReadJSON
+package main
+
+import (
+	"github.com/kataras/iris"
+)
+
+type MyType struct {
+	Name string `url:"name"`
+	Age  int    `url:"age"`
+}
+
+func main() {
+	app := iris.New()
+
+	app.Get("/", func(ctx iris.Context) {
+		var t MyType
+		err := ctx.ReadQuery(&t)
+		if err != nil && !iris.IsErrPath(err) {
+			ctx.StatusCode(iris.StatusInternalServerError)
+			ctx.WriteString(err.Error())
+		}
+
+		ctx.Writef("MyType: %#v", t)
+	})
+
+	// http://localhost:8080?name=iris&age=3
+	app.Run(iris.Addr(":8080"))
+}
diff --git a/context/context.go b/context/context.go
index b40b2512..c59f264c 100644
--- a/context/context.go
+++ b/context/context.go
@@ -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)
 }
 
 //  +------------------------------------------------------------+
diff --git a/doc.go b/doc.go
index ae5417e6..594b0a86 100644
--- a/doc.go
+++ b/doc.go
@@ -38,13 +38,13 @@ Source code and other details for the project are available at GitHub:
 
 Current Version
 
-11.2.0
+11.2.1
 
 Installation
 
 The only requirement is the Go Programming Language, at least version 1.12.
 
-    $ go get github.com/kataras/iris@v11.2.0
+    $ go get github.com/kataras/iris@v11.2.1
 
 Wiki:
 
diff --git a/go.mod b/go.mod
index a3722885..313be63d 100644
--- a/go.mod
+++ b/go.mod
@@ -16,7 +16,6 @@ require (
 	github.com/gavv/httpexpect v2.0.0+incompatible
 	github.com/hashicorp/go-version v1.2.0 // indirect
 	github.com/iris-contrib/blackfriday v2.0.0+incompatible
-	github.com/iris-contrib/formBinder v5.0.0+incompatible
 	github.com/iris-contrib/go.uuid v2.0.0+incompatible
 	github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0
 	github.com/json-iterator/go v1.1.6
@@ -26,4 +25,5 @@ require (
 	github.com/mediocregopher/radix/v3 v3.3.0
 	github.com/microcosm-cc/bluemonday v1.0.2
 	github.com/ryanuber/columnize v2.1.0+incompatible
+	github.com/iris-contrib/schema v0.0.1
 )
diff --git a/go.sum b/go.sum
index ec58ee07..829f1b6a 100644
--- a/go.sum
+++ b/go.sum
@@ -10,8 +10,6 @@ github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4/go.mod h1:T9YF2M40nI
 github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc=
 github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
 github.com/iris-contrib/blackfriday v2.0.0+incompatible/go.mod h1:UzZ2bDEoaSGPbkg6SAB4att1aAwTmVIx/5gCVqeyUdI=
-github.com/iris-contrib/formBinder v5.0.0+incompatible h1:jL+H+cCSEV8yzLwVbBI+tLRN/PpVatZtUZGK9ldi3bU=
-github.com/iris-contrib/formBinder v5.0.0+incompatible/go.mod h1:i8kTYUOEstd/S8TG0ChTXQdf4ermA/e8vJX0+QruD9w=
 github.com/iris-contrib/go.uuid v2.0.0+incompatible h1:XZubAYg61/JwnJNbZilGjf3b3pB80+OQg2qf6c8BfWE=
 github.com/iris-contrib/go.uuid v2.0.0+incompatible/go.mod h1:iz2lgM/1UnEf1kP0L/+fafWORmlnuysV2EMP8MW+qe0=
 github.com/iris-contrib/i18n v0.0.0-20171121225848-987a633949d0/go.mod h1:pMCz62A0xJL6I+umB2YTlFRwWXaDFA0jy+5HzGiJjqI=
@@ -24,3 +22,5 @@ github.com/mediocregopher/radix/v3 v3.3.0/go.mod h1:EmfVyvspXz1uZEyPBMyGK+kjWiKQ
 github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
 github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
 gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+github.com/iris-contrib/schema v0.0.1 h1:10g/WnoRR+U+XXHWKBHeNy/+tZmM2kcAVGLOsz+yaDA=
+github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=