feat(utils): Add functions to parse nullable UUID and UUID from string

This commit is contained in:
Habib Fatkhul Rohman 2025-11-11 11:05:46 +07:00
parent 36dd83d624
commit b619f76c0e
1 changed files with 17 additions and 0 deletions

View File

@ -3,6 +3,7 @@ package utils
import ( import (
"strconv" "strconv"
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt" "golang.org/x/crypto/bcrypt"
) )
@ -31,3 +32,19 @@ func ParseInt(s string) int {
} }
return i return i
} }
func ParseNullableUUID(s *string) *uuid.UUID {
if s == nil || *s == "" {
return nil
}
id := ParseUUID(*s)
return &id
}
func ParseUUID(s string) uuid.UUID {
id, err := uuid.Parse(s)
if err != nil {
return uuid.Nil
}
return id
}