mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
add example for https://github.com/kataras/iris/issues/1671
This commit is contained in:
23
_examples/auth/jwt/tutorial/api/router.go
Normal file
23
_examples/auth/jwt/tutorial/api/router.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"myapp/domain/repository"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
// NewRouter accepts some dependencies
|
||||
// and returns a function which returns the routes on the given Iris Party (group of routes).
|
||||
func NewRouter(userRepo repository.UserRepository, todoRepo repository.TodoRepository) func(iris.Party) {
|
||||
return func(router iris.Party) {
|
||||
router.Post("/signin", SignIn(userRepo))
|
||||
|
||||
router.Use(Verify()) // protect the next routes with JWT.
|
||||
|
||||
router.Post("/todos", CreateTodo(todoRepo))
|
||||
router.Get("/todos", ListTodos(todoRepo))
|
||||
router.Get("/todos/{id}", GetTodo(todoRepo))
|
||||
|
||||
router.Get("/admin/todos", AllowAdmin, ListAllTodos(todoRepo))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user