1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-20 11:27:06 +00:00

Add fallback handlers

Former-commit-id: f7e9bd17076a10e1ed1702780d7ce9e89f00b592
This commit is contained in:
Frédéric Meyer
2018-02-21 12:27:01 +03:00
parent 66209cae4f
commit 72b096e156
10 changed files with 322 additions and 16 deletions

View File

@@ -0,0 +1,29 @@
package main
import (
"github.com/kataras/iris"
)
func main() {
app := iris.New()
// 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"), ctx.Method(), ctx.Path(), iris.WithoutServerError(iris.ErrServerClosed))
}
func h(ctx iris.Context) {
ctx.Writef("[%s] %s : Parameter = `%s`", ctx.Params().Get("p"))
}
func fallbackHandler(ctx iris.Context) {
if ctx.Method() == "DELETE" {
ctx.Next()
return
}
ctx.Writef("[%s] %s : From fallback handler", ctx.Method(), ctx.Path())
}