Documentation ¶
Index ¶
- func IsCreditCardNumber(num string) bool
- func IsIBAN(num string) bool
- func IsIDNumber(idNum string) bool
- func IsIP(address string) bool
- func IsIPPort(address string) bool
- func IsIdentifier(id string) bool
- func IsMobile(mobile string) bool
- func IsNationalCode(idNum string) bool
- func IsPostalcode(postalCode string) bool
- func IsTel(tel string) bool
- func IsUUID(uuid string) bool
- func IsUnsigned(num string) bool
- func IsUsername(username string) bool
- func ValidateUploadExt(file *multipart.FileHeader, exts ...string) (bool, error)
- func ValidateUploadMime(file *multipart.FileHeader, mimes ...string) (bool, error)
- func ValidateUploadSize(file *multipart.FileHeader, min string, max string) (bool, error)
- type ErrorResponse
- type Validator
- type ValidatorParam
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsCreditCardNumber ¶
IsCreditCardNumber check if string is valid credit card number
func IsIdentifier ¶
IsIdentifier check if string is valid identifier
func IsNationalCode ¶ added in v1.0.1
IsNationalCode check if string is valid national code
func IsPostalcode ¶
IsPostalcode check if string is valid postal code
func IsUsername ¶
IsUsername check if string is valid username
func ValidateUploadExt ¶
func ValidateUploadExt(file *multipart.FileHeader, exts ...string) (bool, error)
ValidateUploadExt check if file upload extension is valid
func ValidateUploadMime ¶
func ValidateUploadMime(file *multipart.FileHeader, mimes ...string) (bool, error)
ValidateUploadMime check if file upload mime is valid
func ValidateUploadSize ¶
ValidateUploadSize check if file size in range use B, KB, MB, GB for size string ex: 1KB, 3MB Note: not use float point!
Types ¶
type ErrorResponse ¶
type ErrorResponse interface { // AddError add new error AddError(field, tag, message string) // HasError check if response has error HasError() bool // Failed check if field has error // @example: // resp.Failed("firstname") Failed(field string) bool // FailedOn check if field has special error // @example: // resp.FailedOn("firstname", "required") FailedOn(field, err string) bool // Errors get errors list Errors() map[string]map[string]string // String convert to string String() string // Messages get error messages only without error key Messages() map[string][]string // Rules get error rules only without error message Rules() map[string][]string // MarshalJSON convert to json MarshalJSON() ([]byte, error) }
ErrorResponse interface
func Invalidate ¶
func Invalidate(field, err string) ErrorResponse
Invalidate generate invalid state for field
func NewErrorResponse ¶
func NewErrorResponse() ErrorResponse
NewErrorResponse create new error response instance
type Validator ¶
type Validator interface { // Validator get original validator instance Validator() *validator.Validate // AddValidation add new validator AddValidation(tag string, v validator.Func) // AddTranslation register new translation message to validator translator AddTranslation(locale string, key string, message string) // Translate generate translation Translate(locale string, key string, placeholders map[string]string) string // TranslateStruct generate translation for struct TranslateStruct(s any, locale string, key string, field string, placeholders map[string]string) string // Struct validates a structs exposed fields, and automatically validates nested structs, unless otherwise specified. // Return translated errors list on fails // Return nil on no error // use vTitle tag for define field title, (use vTitle_locale) for localization // use vParam tag for define param title in multifield validations (like eqcsfield). this tag follow vTitle tag rules // use vFormat tag for format parameter as number StructLocale(locale string, s any) ErrorResponse // Validate using default locale // @see StructLocale Struct(s any) ErrorResponse // StructExcept validates all fields except the ones passed in. // Return translated errors list on fails // Return nil on no error StructExceptLocale(locale string, s any, fields ...string) ErrorResponse // Validate using default locale // @see StructExceptLocale StructExcept(s any, fields ...string) ErrorResponse // StructPartial validates the fields passed in only, ignoring all others. // Return translated errors list on fails // Return nil on no error StructPartialLocale(locale string, s any, fields ...string) ErrorResponse // Validate using default locale // @see StructPartialLocale StructPartial(s any, fields ...string) ErrorResponse // Var validates a single variable using tag style validation. // Return translated errors list on fails // Return nil on no error VarLocale(locale string, params ValidatorParam, field any, tag string, messages map[string]string) ErrorResponse // Validate using default locale // @see VarLocale Var(params ValidatorParam, field any, tag string, messages map[string]string) ErrorResponse // VarWithValue validates a single variable, against another variable/field's value using tag style validation // Return translated errors list on fails // Return nil on no error VarWithValueLocale(locale string, params ValidatorParam, field any, other any, tag string, messages map[string]string) ErrorResponse // Validate using default locale // @see VarWithValueLocale VarWithValue(params ValidatorParam, field any, other any, tag string, messages map[string]string) ErrorResponse }
Validator interface
func NewValidator ¶
func NewValidator(t translator.Translator, locale string) Validator
NewValidator create new validator