iris/_examples/auth/jwt/tutorial/main.go

41 lines
1019 B
Go
Raw Normal View History

package main
import (
2020-11-04 20:12:13 +01:00
"myapp/api"
"myapp/domain/repository"
"github.com/kataras/iris/v12"
)
var (
2020-11-04 20:12:13 +01:00
userRepository = repository.NewMemoryUserRepository()
todoRepository = repository.NewMemoryTodoRepository()
)
func main() {
2020-11-04 20:12:13 +01:00
if err := repository.GenerateSamples(userRepository, todoRepository); err != nil {
panic(err)
}
2020-11-04 20:12:13 +01:00
app := iris.New()
2020-11-04 20:12:13 +01:00
app.Post("/signin", api.SignIn(userRepository))
2020-11-04 20:12:13 +01:00
verify := api.Verify()
2020-11-04 20:12:13 +01:00
todosAPI := app.Party("/todos", verify)
todosAPI.Post("/", api.CreateTodo(todoRepository))
todosAPI.Get("/", api.ListTodos(todoRepository))
todosAPI.Get("/{id}", api.GetTodo(todoRepository))
2020-11-04 20:12:13 +01:00
adminAPI := app.Party("/admin", verify, api.AllowAdmin)
adminAPI.Get("/todos", api.ListAllTodos(todoRepository))
2020-11-04 20:12:13 +01:00
// POST http://localhost:8080/signin (Form: username, password)
// GET http://localhost:8080/todos
// GET http://localhost:8080/todos/{id}
// POST http://localhost:8080/todos (JSON, Form or URL: title, body)
// GET http://localhost:8080/admin/todos
app.Listen(":8080")
}