Documentation
¶
Index ¶
- Constants
- Variables
- func Boolean(field, value string) (bool, string)
- func Email(field, value string) (bool, string)
- func Required(field, value string) (bool, string)
- type FileValidationConfig
- type HTTPValidator
- type ValidationFunc
- type Validator
- func (v *Validator) Check(ok bool, field, message string)
- func (v *Validator) GetFile(field string) *multipart.FileHeader
- func (v *Validator) GetValue(field string) string
- func (v *Validator) Image(field string, config FileValidationConfig) *multipart.FileHeader
- func (v *Validator) Int(field string, validations ...ValidationFunc) int64
- func (v *Validator) SetFile(field string, file *multipart.FileHeader)
- func (v *Validator) SetValue(field, value string)
- func (v *Validator) String(field string, validations ...ValidationFunc) string
- func (v *Validator) Valid() bool
Constants ¶
const ( MimeJPEG = "image/jpeg" MimePNG = "image/png" MimeGIF = "image/gif" MimeWEBP = "image/webp" )
Common MIME types for images.
const ( KB = 1024 MB = 1024 * KB )
Common file size constants.
Variables ¶
var DefaultImageFormats = []string{"jpg", "jpeg", "png", "gif", "webp"}
Default image formats.
Functions ¶
Types ¶
type FileValidationConfig ¶
type FileValidationConfig struct {
MaxSize int64 // maximum file size in bytes.
AllowedTypes []string // allowed MIME types.
AllowedExts []string // allowed file extensions.
}
Add new types and constants for file validation.
func ImageConfig ¶
func ImageConfig(maxSize int64, formats ...string) FileValidationConfig
ImageConfig creates a standard image validation configuration.
type HTTPValidator ¶
type HTTPValidator struct {
*Validator
// contains filtered or unexported fields
}
HTTPValidator extends Validator to work with http.Request.
type ValidationFunc ¶
ValidationFunc represents a validation function.
func Custom ¶
func Custom(check func(string) bool, message string) ValidationFunc
Custom creates a validation function from a custom check.
func InStringSlice ¶
func InStringSlice(slice []string) ValidationFunc
InStringSlice creates a validation function that checks if a value exists in a slice.
func IntRange ¶
func IntRange(min, max int) ValidationFunc
IntRange creates a validation function for integer range.
func Matches ¶
func Matches(pattern string, message string) ValidationFunc
Matches creates a validation function for regex pattern matching
func MaxLength ¶
func MaxLength(max int) ValidationFunc
MaxLength creates a validation function for maximum length
func MinLength ¶
func MinLength(min int) ValidationFunc
MinLength creates a validation function for minimum length
type Validator ¶
Validator holds the validation errors and form values.
func (*Validator) GetFile ¶
func (v *Validator) GetFile(field string) *multipart.FileHeader
Add method to get file.
func (*Validator) Image ¶
func (v *Validator) Image(field string, config FileValidationConfig) *multipart.FileHeader
Image validates an image file field.
func (*Validator) Int ¶
func (v *Validator) Int(field string, validations ...ValidationFunc) int64
Int validates and returns an integer field.
func (*Validator) SetFile ¶
func (v *Validator) SetFile(field string, file *multipart.FileHeader)
Add method to set file.