iris/_examples/http_request/read-query/main.go
Gerasimos (Makis) Maropoulos f3745cebbd replace all common error responses with the new Context.StopWithError
Former-commit-id: 99b08a0b5564ef640456db12674cb37721f73ae3
2020-05-18 00:25:38 +03:00

30 lines
584 B
Go

// 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/v12"
)
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.StopWithError(iris.StatusInternalServerError, err)
return
}
ctx.Writef("MyType: %#v", t)
})
// http://localhost:8080?name=iris&age=3
app.Listen(":8080")
}