Documentation
¶
Index ¶
Constants ¶
View Source
const ( CodePasswordRequired = 2001 CodeMobileInvalid = 2002 CodeFieldInvalid = 2003 )
Validation error codes.
Variables ¶
View Source
var ( ErrPasswordRequired = &ValidationError{Code: CodePasswordRequired, Message: "password must contain uppercase and lowercase letters and digits, with a minimum length of 8"} ErrMobileInvalid = &ValidationError{Code: CodeMobileInvalid, Message: "invalid mobile phone number format"} ErrFieldInvalid = &ValidationError{Code: CodeFieldInvalid, Message: "validation failed"} )
Pre-defined validation errors. Use errors.Is/As to match.
Functions ¶
func IsValidationError ¶
IsValidationError returns true if err is or wraps a ValidationError.
func ValidationErrorCode ¶
ValidationErrorCode extracts the error code from a ValidationError. Returns 0 if err is not a ValidationError.
Types ¶
type ValidationError ¶
type ValidationError struct {
Code int `json:"code"`
Message string `json:"message"`
Field string `json:"field,omitempty"`
}
ValidationError is a structured error for validation failures. Supports errors.Is matching by error code.
func NewValidationError ¶
func NewValidationError(code int, msg string) *ValidationError
NewValidationError creates a new ValidationError with the given code and message.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error implements the error interface.
func (*ValidationError) Is ¶
func (e *ValidationError) Is(target error) bool
Is enables errors.Is matching by error code. Returns true if target is a *ValidationError with the same Code.
Click to show internal directories.
Click to hide internal directories.