iris/_examples/miscellaneous/recover/main.go
Gerasimos (Makis) Maropoulos 247a558394 Add example for struct validation(3rd-party) through json request body binding
Former-commit-id: 78bbbe068f219e5a264951c900b77cb9b70f2079
2018-07-24 04:33:53 +03:00

29 lines
555 B
Go

package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/recover"
)
func main() {
app := iris.New()
app.Use(recover.New())
i := 0
// let's simulate a panic every next request
app.Get("/", func(ctx iris.Context) {
i++
if i%2 == 0 {
panic("a panic here")
}
ctx.Writef("Hello, refresh one time more to get panic!")
})
// http://localhost:8080, refresh it 5-6 times.
app.Run(iris.Addr(":8080"))
}
// Note:
// app := iris.Default() instead of iris.New() makes use of the recovery middleware automatically.