2019-07-24 02:29:42 +02:00
|
|
|
// 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 (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2019-07-24 02:29:42 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2019-07-24 02:29:42 +02:00
|
|
|
}
|