iris/_examples/routing/fallback-handlers/main.go
Gerasimos (Makis) Maropoulos d7beb9a752 Add a missing call for fallbackHandler in _examples/routing/fallback-handlers/main.go by @ZaniaDeveloper via PR: #911
Former-commit-id: 94ae5849e16538a4bc7f906c52ed7603c7ae01f6
2018-02-23 15:20:53 +02:00

30 lines
729 B
Go

package main
import "github.com/kataras/iris"
func main() {
app := iris.New()
// add a fallback handler to process requests that would not be declared in the router.
app.Fallback(fallbackHandler)
// this works as expected now,
// will handle *all* expect DELETE requests, even if there is no routes.
app.Get("/action/{p}", h)
app.Run(iris.Addr(":8080"), iris.WithoutServerError(iris.ErrServerClosed))
}
func h(ctx iris.Context) {
ctx.Writef("[%s] %s : Parameter = `%s`", ctx.Method(), ctx.Path(), ctx.Params().Get("p"))
}
func fallbackHandler(ctx iris.Context) {
if ctx.Method() == iris.MethodDelete {
ctx.NextOrNotFound()
return
}
ctx.Writef("[%s] %s : From fallback handler", ctx.Method(), ctx.Path())
}