prompt-5
This commit is contained in:
@@ -2,14 +2,45 @@ package http
|
||||
|
||||
import (
|
||||
"trustcontact/internal/config"
|
||||
httpmw "trustcontact/internal/http/middleware"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func RegisterRoutes(app *fiber.App, _ *session.Store, _ *gorm.DB, _ *config.Config) {
|
||||
func RegisterRoutes(app *fiber.App, store *session.Store, database *gorm.DB, _ *config.Config) {
|
||||
app.Use(httpmw.SessionStoreMiddleware(store))
|
||||
app.Use(httpmw.CurrentUserMiddleware(store, database))
|
||||
app.Use(httpmw.ConsumeFlash())
|
||||
|
||||
app.Get("/healthz", func(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
})
|
||||
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "public")
|
||||
httpmw.SetTemplateData(c, "NavSection", "public")
|
||||
return c.SendString("public area")
|
||||
})
|
||||
|
||||
app.Get("/login", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "public")
|
||||
httpmw.SetTemplateData(c, "NavSection", "public")
|
||||
return c.SendString("login page")
|
||||
})
|
||||
|
||||
private := app.Group("/private", httpmw.RequireAuth())
|
||||
private.Get("/", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "private")
|
||||
httpmw.SetTemplateData(c, "NavSection", "private")
|
||||
return c.SendString("private area")
|
||||
})
|
||||
|
||||
admin := app.Group("/admin", httpmw.RequireAuth(), httpmw.RequireAdmin())
|
||||
admin.Get("/", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "admin")
|
||||
httpmw.SetTemplateData(c, "NavSection", "admin")
|
||||
return c.SendString("admin area")
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user