123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package router
- import (
- "github.com/dmitriygnatenko/internal/interfaces"
- "github.com/dmitriygnatenko/internal/services/handler"
- adminHandler "github.com/dmitriygnatenko/internal/services/handler/admin"
- "github.com/gofiber/fiber/v2"
- "github.com/gofiber/fiber/v2/middleware/basicauth"
- "github.com/gofiber/fiber/v2/middleware/monitor"
- )
- type Route struct {
- Method string
- Path string
- Handlers []fiber.Handler
- }
- func ApplyRoutes(app interfaces.IApp) {
- f := app.GetFiber()
- f.Get("/", handler.MainPageHandler(app))
- f.Get("/tag/:tag", handler.TagHandler(app))
- f.Get("/article/:article", handler.ArticleHandler(app))
- // Admin
- user := app.GetEnvService().GetAdminUser()
- password := app.GetEnvService().GetAdminPassword()
- if user != "" && password != "" {
- admin := f.Group("/admin", basicauth.New(basicauth.Config{
- Users: map[string]string{
- user: password,
- },
- }))
- admin.Get("/metrics", monitor.New(monitor.Config{}))
- admin.Get("/", adminHandler.ArticleHandler(app))
- admin.All("/article/add", adminHandler.AddArticleHandler(app))
- admin.All("/article/edit/:id<int>", adminHandler.EditArticleHandler(app))
- admin.All("/article/delete/:id<int>", adminHandler.DeleteArticleHandler(app))
- admin.Get("/tag", adminHandler.TagHandler(app))
- admin.All("/tag/add", adminHandler.AddTagHandler(app))
- admin.All("/tag/edit/:id<int>", adminHandler.EditTagHandler(app))
- admin.All("/tag/delete/:id<int>", adminHandler.DeleteTagHandler(app))
- }
- }
|