mirror of
https://github.com/kataras/iris.git
synced 2025-12-19 10:57:05 +00:00
Add a third, simple, example for folder structuring as requested at https://github.com/kataras/iris/issues/748
One change to code base but it will be described at the next version: Error Handlers (`app.OnErrorCode/OnAnyErrorCode`) respect the `app.UseGlobal`'s middlewares now (not the `app.Use` for reasons we can all understand, hopefully). Former-commit-id: ec97bbb04548f9932cf4d7b950be513b70747bcb
This commit is contained in:
11
_examples/structuring/handler-based/routes/follower.go
Normal file
11
_examples/structuring/handler-based/routes/follower.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
// GetFollowerHandler handles the GET: /follower/{id}
|
||||
func GetFollowerHandler(ctx iris.Context) {
|
||||
id, _ := ctx.Params().GetInt64("id")
|
||||
ctx.Writef("from "+ctx.GetCurrentRoute().Path()+" with ID: %d", id)
|
||||
}
|
||||
11
_examples/structuring/handler-based/routes/following.go
Normal file
11
_examples/structuring/handler-based/routes/following.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
// GetFollowingHandler handles the GET: /following/{id}
|
||||
func GetFollowingHandler(ctx iris.Context) {
|
||||
id, _ := ctx.Params().GetInt64("id")
|
||||
ctx.Writef("from "+ctx.GetCurrentRoute().Path()+" with ID: %d", id)
|
||||
}
|
||||
11
_examples/structuring/handler-based/routes/index.go
Normal file
11
_examples/structuring/handler-based/routes/index.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
// GetIndexHandler handles the GET: /
|
||||
func GetIndexHandler(ctx iris.Context) {
|
||||
ctx.ViewData("Title", "Index Page")
|
||||
ctx.View("index.html")
|
||||
}
|
||||
11
_examples/structuring/handler-based/routes/like.go
Normal file
11
_examples/structuring/handler-based/routes/like.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
// GetLikeHandler handles the GET: /like/{id}
|
||||
func GetLikeHandler(ctx iris.Context) {
|
||||
id, _ := ctx.Params().GetInt64("id")
|
||||
ctx.Writef("from "+ctx.GetCurrentRoute().Path()+" with ID: %d", id)
|
||||
}
|
||||
14
_examples/structuring/handler-based/routes/routes.go
Normal file
14
_examples/structuring/handler-based/routes/routes.go
Normal file
@@ -0,0 +1,14 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/_examples/structuring/handler-based/bootstrap"
|
||||
)
|
||||
|
||||
// Configure registers the nessecary routes to the app.
|
||||
func Configure(b *bootstrap.Bootstrapper) {
|
||||
// routes
|
||||
b.Get("/", GetIndexHandler)
|
||||
b.Get("/follower/{id:long}", GetFollowerHandler)
|
||||
b.Get("/following/{id:long}", GetFollowingHandler)
|
||||
b.Get("/like/{id:long}", GetLikeHandler)
|
||||
}
|
||||
Reference in New Issue
Block a user