migrate to fiber

This commit is contained in:
Zoe
2024-10-01 03:45:43 -05:00
parent e39e5f51fd
commit e64b9fba7f
17 changed files with 587 additions and 372 deletions

View File

@@ -4,19 +4,19 @@ import (
"filething/models"
"net/http"
"github.com/gofiber/fiber/v3"
"github.com/labstack/echo/v4"
"github.com/uptrace/bun"
)
func AdminMiddleware() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
user := c.Get("user").(*models.User)
func AdminMiddleware(db *bun.DB) func(c fiber.Ctx) error {
return func(c fiber.Ctx) error {
user := c.Locals("user").(*models.User)
if !user.Admin {
return echo.NewHTTPError(http.StatusForbidden, "You are not an administrator")
}
return next(c)
if !user.Admin {
return echo.NewHTTPError(http.StatusForbidden, "You are not an administrator")
}
return c.Next()
}
}