Documentation ¶
Index ¶
- Constants
- Variables
- func ValidateEmail(s string) error
- func ValidateFile(file *multipart.FileHeader, field string, validators ...fileValidationFunc) url.Values
- func ValidateFileContentType(contentTypes ...string) fileValidationFunc
- func ValidateFileFromRequest(r *http.Request, field string, validators ...fileValidationFunc) url.Values
- func ValidateFileSize(min, max string) fileValidationFunc
- func ValidateImage(file *multipart.FileHeader, field, min, max string) url.Values
- func ValidateSolanaWalletAddr(addr string) error
- func ValidateStruct(s interface{}) url.Values
- type EmailAddress
- type ValidationError
Constants ¶
const ( // Predefined image content types ImageContentTypeJpeg = "image/jpeg" ImageContentTypePng = "image/png" ImageContentTypeGif = "image/gif" )
Variables ¶
var ( ErrFileSizeLt = errors.New("file size is less than") ErrFileSizeGt = errors.New("file size is greater than") ErrInvalidFileContentType = errors.New("invalid file content type") )
Predefined errors
var DefaultFormMaxMemory int64 = 32 << 20 // 32 MB
DefaultFormMaxMemory is the default maximum amount of memory to use when parsing a multipart form.
var ErrValidation = errors.New("validation_failed")
ErrValidation is returned when validation fails.
Functions ¶
func ValidateEmail ¶
Email is a validator that checks if the value is a valid email address.
func ValidateFile ¶
func ValidateFile(file *multipart.FileHeader, field string, validators ...fileValidationFunc) url.Values
ValidateFile validates file size and content type. It returns url.Values if there is an error otherwise it returns nil.
func ValidateFileContentType ¶
func ValidateFileContentType(contentTypes ...string) fileValidationFunc
ValidateFileContentType validates file content type. It returns url.Values if there is an error otherwise it returns nil.
func ValidateFileFromRequest ¶
func ValidateFileFromRequest(r *http.Request, field string, validators ...fileValidationFunc) url.Values
ValidateFileFromRequest validates file size and content type from multipart form request. It returns url.Values if there is an error otherwise it returns nil.
func ValidateFileSize ¶
func ValidateFileSize(min, max string) fileValidationFunc
ValidateFileSize validates file size.
func ValidateImage ¶
func ValidateImage(file *multipart.FileHeader, field, min, max string) url.Values
ValidateImage validates image file size and content type. It returns url.Values if there is an error otherwise it returns nil.
func ValidateSolanaWalletAddr ¶
ValidateSolanaWalletAddr validates a Solana wallet address. Returns an error if the address is invalid, nil otherwise.
func ValidateStruct ¶
ValidateStruct validate struct data - s: struct pointer - return: validation errors as url.Values or nil if no errors
Types ¶
type EmailAddress ¶
type EmailAddress struct { // LocalPart usually the username of an email address. LocalPart string // Domain is the part of the email address after the last @. // This should be DNS resolvable to an email server. Domain string }
EmailAddress is a structure that stores the address local-part@domain parts.
func (EmailAddress) String ¶
func (e EmailAddress) String() string
func (EmailAddress) ValidateHost ¶
func (e EmailAddress) ValidateHost() error
ValidateHost will test if the email address is actually reachable. It will first try to resolve the host and then start a mail transaction.
func (EmailAddress) ValidateIcanSuffix ¶
func (e EmailAddress) ValidateIcanSuffix() error
ValidateIcanSuffix will test if the public suffix of the domain is managed by ICANN using the golang.org/x/net/publicsuffix package. If not it will return an error. Note that if this method returns an error it does not necessarily mean that the email address is invalid. Also the suffix list in the standard package is embedded and thereby not up to date.
type ValidationError ¶
type ValidationError struct { Err error // The underlying error. Values url.Values // A map of field names to error messages. }
ValidationError is a custom error type that contains a map of field names to error messages.
func NewValidationError ¶
func NewValidationError(values url.Values) *ValidationError
NewValidationError returns a new ValidationError.
func (*ValidationError) AddValue ¶
func (e *ValidationError) AddValue(key, message string) *ValidationError
AddValue adds a new error message to the map.
func (*ValidationError) AddValues ¶
func (e *ValidationError) AddValues(values url.Values) *ValidationError
AddValues adds a new error message to the map.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error returns the error message.
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Unwrap returns the underlying error.