1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-17 09:57:01 +00:00
Files
kararas_iris/_examples/routing/route-register-rule/main.go
Gerasimos (Makis) Maropoulos 43502ed047 minor
Former-commit-id: 26b0b59ba54caac38d726d7fec562a5d6a0a76e3
2020-06-18 09:36:47 +03:00

46 lines
1.3 KiB
Go

package main
import "github.com/kataras/iris/v12"
func main() {
app := newApp()
// Navigate through https://github.com/kataras/iris/issues/1448 for details.
//
// GET: http://localhost:8080
// POST, PUT, DELETE, CONNECT, HEAD, PATCH, OPTIONS, TRACE : http://localhost:8080
app.Listen(":8080")
}
func newApp() *iris.Application {
app := iris.New()
// Skip and do NOT override existing regitered route, continue normally.
// Applies to a Party and its children, in this case the whole application's routes.
app.SetRegisterRule(iris.RouteSkip)
/* Read also:
// The default behavior, will override the getHandler to anyHandler on `app.Any` call.
app.SetRegistRule(iris.RouteOverride)
// Stops the execution and fires an error before server boot.
app.SetRegisterRule(iris.RouteError)
// If ctx.StopExecution or StopWithXXX then the next route will be executed
// (see mvc/authenticated-controller example too).
app.SetRegisterRule(iris.RouteOverlap)
*/
app.Get("/", getHandler)
// app.Any does NOT override the previous GET route because of `iris.RouteSkip` rule.
app.Any("/", anyHandler)
return app
}
func getHandler(ctx iris.Context) {
ctx.Writef("From GET: %s", ctx.GetCurrentRoute().MainHandlerName())
}
func anyHandler(ctx iris.Context) {
ctx.Writef("From %s: %s", ctx.Method(), ctx.GetCurrentRoute().MainHandlerName())
}