You've already forked reloading-manager
No changes made
This commit is contained in:
45
backend/handlers/uuid.go
Normal file
45
backend/handlers/uuid.go
Normal file
@@ -0,0 +1,45 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"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, err
|
||||
}
|
||||
|
||||
return &pgtype.UUID{
|
||||
Bytes: uid,
|
||||
Valid: true,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func ParseUuidOrBadRequest(c echo.Context, s string) *pgtype.UUID {
|
||||
uid, err := ParseUuid(s)
|
||||
if err != nil {
|
||||
_ = BadRequest(c, "Invalid UUID.")
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return uid
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user