Files
reloading-manager/backend/handlers/uuid.go
Ron Rise 45b33d1ad8
Some checks failed
🧪 ✨ Unit Tests Workflow / 🧪 📜 JavaScript Tests (push) Successful in 1m38s
🧪 ✨ Unit Tests Workflow / 🧪 🐹 GolangCI-Lint (push) Failing after 2m36s
🧪 ✨ Unit Tests Workflow / 🔍 🐹 Go Tests (push) Successful in 3m50s
I'll explain when you're older!
2025-06-10 08:36:02 -04:00

44 lines
763 B
Go

package handlers
import (
"fmt"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/labstack/echo/v4"
)
func ParseUuidOrEmpty(s string) *pgtype.UUID {
ParsedUuid, err := uuid.Parse(s)
if err != nil {
return &pgtype.UUID{
Valid: false,
}
}
return &pgtype.UUID{
Bytes: ParsedUuid,
Valid: true,
}
}
func ParseUuid(s string) (*pgtype.UUID, error) {
uid, err := uuid.Parse(s)
if err != nil {
return nil, fmt.Errorf("invalid UUID format: %v", err)
}
return &pgtype.UUID{
Bytes: uid,
Valid: true,
}, nil
}
func ParseUuidOrBadRequest(c echo.Context, s string) (*pgtype.UUID, error) {
uid, err := ParseUuid(s)
if err != nil {
return nil, BadRequest(c, fmt.Sprintf("invalid UUID. %v", err))
}
return uid, nil
}