add all validator, simplify error messages

This commit is contained in:
Aneurin Barker Snook
2023-10-07 13:42:17 +01:00
parent c2efe16dc0
commit c74486d122
8 changed files with 98 additions and 19 deletions
+6 -1
View File
@@ -5,13 +5,18 @@ import (
"regexp"
)
// Validation error.
var (
ErrInvalidUUID = errors.New("invalid UUID")
)
var uuidRegexp = regexp.MustCompile("^[a-f0-9]{8}(-[a-f0-9]{4}){3}-[a-f0-9]{12}$")
// UUID validates a UUID string.
// The UUID must be formatted with separators.
func UUID(value string) error {
if !uuidRegexp.MatchString(value) {
return errors.New("Invalid UUID")
return ErrInvalidUUID
}
return nil