1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +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

@@ -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"))
}