Bind Query String

The ReadQuery method only binds the query params and not the post data, use ReadForm instead to bind post data.

  1. package main
  2. import "github.com/kataras/iris/v12"
  3. type Person struct {
  4. Name string `url:"name,required"`
  5. Address string `url:"address"`
  6. }
  7. func main() {
  8. app := iris.Default()
  9. app.Any("/", index)
  10. app.Listen(":8080")
  11. }
  12. func index(ctx iris.Context) {
  13. var person Person
  14. if err := ctx.ReadQuery(&person); err!=nil {
  15. ctx.StopWithError(iris.StatusBadRequest, err)
  16. return
  17. }
  18. ctx.Application().Logger().Infof("Person: %#+v", person)
  19. ctx.WriteString("Success")
  20. }