iris/_examples/miscellaneous/recover/main.go
Kimmo Hintikka d4b09987c4 corrected spelling for example docs
Corrected spelling from simmilate to simulate

Former-commit-id: f672aa340fd53119defa89da0d93757dc0b0152b
2018-01-22 11:04:33 +00:00

30 lines
590 B
Go

package main
import (
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/recover"
)
func main() {
app := iris.New()
// use this recover(y) middleware
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.