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:
29
_examples/routing/fallback-handlers/main.go
Normal file
29
_examples/routing/fallback-handlers/main.go
Normal 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())
|
||||
}
|
||||
Reference in New Issue
Block a user