1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 18:37:05 +00:00

add new ':email' path parameter and revert the jsoniter removal

This commit is contained in:
Gerasimos (Makis) Maropoulos
2021-10-13 16:22:22 +03:00
parent a9b97e005a
commit bf54d33a3e
15 changed files with 179 additions and 101 deletions

View File

@@ -34,7 +34,12 @@ func main() {
app.Post("/decode", func(ctx iris.Context) {
// Read https://github.com/kataras/iris/blob/master/_examples/request-body/read-json/main.go as well.
var user User
ctx.ReadJSON(&user)
err := ctx.ReadJSON(&user)
if err != nil {
ctx.StatusCode(iris.StatusBadRequest)
ctx.Writef("unable to read body: %s\nbody is empty: %v", err.Error(), iris.IsErrEmptyJSON(err))
return
}
ctx.Writef("%s %s is %d years old and comes from %s!", user.Firstname, user.Lastname, user.Age, user.City)
})