-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherrors.go
More file actions
47 lines (42 loc) · 1.46 KB
/
Copy patherrors.go
File metadata and controls
47 lines (42 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package validatorgo
import "fmt"
// Error code constants for validation failures.
const (
ErrInvalidFormat = "invalid_format"
ErrTooShort = "too_short"
ErrTooLong = "too_long"
ErrMissingTLD = "missing_tld"
ErrBlacklistedHost = "blacklisted_host"
ErrNotWhitelistedHost = "not_whitelisted_host"
ErrBlacklistedChar = "blacklisted_char"
ErrInvalidLocale = "invalid_locale"
ErrOutOfRange = "out_of_range"
ErrInvalidChecksum = "invalid_checksum"
ErrInvalidLength = "invalid_length"
ErrMissingRequired = "missing_required"
ErrInvalidDomain = "invalid_domain"
ErrUnsupportedVersion = "unsupported_version"
ErrInvalidValue = "invalid_value"
ErrNotFound = "not_found"
)
// ValidationError represents a validation failure with context about why it failed.
type ValidationError struct {
// Validator is the name of the validator function that failed (e.g., "IsEmail").
Validator string
// Code is a machine-readable error code (e.g., ErrInvalidFormat).
Code string
// Message is a human-readable description of the failure.
Message string
}
// Error implements the error interface.
func (e *ValidationError) Error() string {
return fmt.Sprintf("%s: %s", e.Validator, e.Message)
}
// newValidationError creates a new ValidationError.
func newValidationError(validator, code, message string) error {
return &ValidationError{
Validator: validator,
Code: code,
Message: message,
}
}