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", adminHandler.EditArticleHandler(app)) admin.All("/article/delete/:id", adminHandler.DeleteArticleHandler(app)) admin.Get("/tag", adminHandler.TagHandler(app)) admin.All("/tag/add", adminHandler.AddTagHandler(app)) admin.All("/tag/edit/:id", adminHandler.EditTagHandler(app)) admin.All("/tag/delete/:id", adminHandler.DeleteTagHandler(app)) } }