@@ -23,7 +23,6 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
uuidRegex = regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
|
||||
domainRegex = regexp.MustCompile(`^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)*[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$`)
|
||||
)
|
||||
|
||||
@@ -61,40 +60,6 @@ func URL() ValidatorFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// HTTPUrl validates that a string is a valid HTTP URL (not HTTPS).
|
||||
func HTTPUrl() ValidatorFunc {
|
||||
return func(value any) *ValidationError {
|
||||
actualValue, isNil := dereferenceValue(value)
|
||||
if isNil {
|
||||
return nil
|
||||
}
|
||||
|
||||
str, ok := actualValue.(string)
|
||||
if !ok {
|
||||
return newValidationError(ErrorCodeInvalidURL, "value must be a string")
|
||||
}
|
||||
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsedURL, err := url.Parse(str)
|
||||
if err != nil {
|
||||
return newValidationError(ErrorCodeInvalidURL, "invalid URL format")
|
||||
}
|
||||
|
||||
if parsedURL.Scheme != "http" {
|
||||
return newValidationError(ErrorCodeInvalidURL, "URL must use http scheme")
|
||||
}
|
||||
|
||||
if parsedURL.Host == "" {
|
||||
return newValidationError(ErrorCodeInvalidURL, "URL must have a host")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// HTTPSUrl validates that a string is a valid HTTPS URL (not HTTP).
|
||||
func HTTPSUrl() ValidatorFunc {
|
||||
return func(value any) *ValidationError {
|
||||
@@ -129,31 +94,6 @@ func HTTPSUrl() ValidatorFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// UUID validates that a string is a valid UUID.
|
||||
func UUID() ValidatorFunc {
|
||||
return func(value any) *ValidationError {
|
||||
actualValue, isNil := dereferenceValue(value)
|
||||
if isNil {
|
||||
return nil
|
||||
}
|
||||
|
||||
str, ok := actualValue.(string)
|
||||
if !ok {
|
||||
return newValidationError(ErrorCodeInvalidFormat, "value must be a string")
|
||||
}
|
||||
|
||||
if str == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
if !uuidRegex.MatchString(str) {
|
||||
return newValidationError(ErrorCodeInvalidFormat, "invalid UUID format")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// GID validates that a string is a valid GID using gid.ParseGID.
|
||||
// Optionally validates the entity type if provided.
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user