1
0
mirror of https://github.com/kataras/iris.git synced 2025-12-18 02:17:05 +00:00

implement #1536 with (SetRegisterRule(iris.RouteOverlap))

Former-commit-id: 2b5523ff3e2aab60dd83faa3c520b16a34916fbe
This commit is contained in:
Gerasimos (Makis) Maropoulos
2020-06-14 08:09:42 +03:00
parent 78a45163e3
commit ed5964716b
16 changed files with 210 additions and 24 deletions

View File

@@ -26,6 +26,11 @@ func main() {
userRouter := app.Party("/user")
{
// Use that in order to be able to register a route twice,
// last one will be executed if the previous route's handler(s) stopped and the response can be reset-ed.
// See core/router/route_register_rule_test.go#TestRegisterRuleOverlap.
userRouter.SetRegisterRule(iris.RouteOverlap)
// Initialize a new MVC application on top of the "userRouter".
userApp := mvc.New(userRouter)
// Register Dependencies.
@@ -34,6 +39,7 @@ func main() {
// Register Controllers.
userApp.Handle(new(MeController))
userApp.Handle(new(UserController))
userApp.Handle(new(UnauthenticatedUserController))
}
// Open a client, e.g. Postman and visit the below endpoints.
@@ -61,6 +67,15 @@ func authDependency(ctx iris.Context, session *sessions.Session) Authenticated {
return Authenticated(userID)
}
// UnauthenticatedUserController serves the "public" Unauthorized User API.
type UnauthenticatedUserController struct{}
// GetMe registers a route that will be executed when authentication is not passed
// (see UserController.GetMe) too.
func (c *UnauthenticatedUserController) GetMe() string {
return `custom action to redirect on authentication page`
}
// UserController serves the "public" User API.
type UserController struct {
Session *sessions.Session