chore(migrate) moved codebase from lab4

This commit is contained in:
Mikhail Verkovykh
2026-11-14 23:17:36 +03:00
parent 276dbdad8a
commit 28d68dc30b
123 changed files with 11677 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package common
import (
"github.com/gofiber/fiber/v3"
"github.com/google/uuid"
)
const (
KeyUserID = "userID"
KeySessionToken = "sessionToken"
)
func UserID(c fiber.Ctx) (uuid.UUID, bool) {
userID, ok := c.Locals(KeyUserID).(uuid.UUID)
return userID, ok
}
func MustUserID(c fiber.Ctx) uuid.UUID {
userID, ok := UserID(c)
if !ok {
panic("common: authenticated user ID is missing from the request context")
}
return userID
}
func SessionToken(c fiber.Ctx) (string, bool) {
token, ok := c.Locals(KeySessionToken).(string)
return token, ok && token != ""
}
// PathUUID parses a UUID path parameter. A malformed value is a contract
// invalid_request, not a lookup failure.
func PathUUID(c fiber.Ctx, name string) (uuid.UUID, error) {
id, err := uuid.Parse(c.Params(name))
if err != nil {
return uuid.Nil, BadRequest("invalid " + name + " format")
}
return id, nil
}