Documentation
¶
Index ¶
- Variables
- func MustRegisterValidation(name string, r *ValidationRegistration)
- func RegisterValidation(name string, r *ValidationRegistration) error
- type CustomValidation
- type FieldContext
- type FieldData
- type FieldError
- type Func
- type FuncCtx
- type ImportData
- type StructData
- type Validable
- type ValidateValidationField
- type ValidationData
- type ValidationErrors
- type ValidationGenerationFunc
- type ValidationPair
- type ValidationRegistration
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrRequired = errors.New("field required") ErrIsDefault = errors.New("field must have default value") ErrInvalidFormat = errors.New("invalid format") ErrEmail = errors.Wrap(ErrInvalidFormat, "invalid email") ErrMin = errors.New("min validation not satisfied") ErrMax = errors.New("max validation not satisfied") )
View Source
var ( AlphaRegex = regexp.MustCompile(alphaRegexString) AlphaNumericRegex = regexp.MustCompile(alphaNumericRegexString) AlphaUnicodeRegex = regexp.MustCompile(alphaUnicodeRegexString) AlphaUnicodeNumericRegex = regexp.MustCompile(alphaUnicodeNumericRegexString) NumericRegex = regexp.MustCompile(numericRegexString) NumberRegex = regexp.MustCompile(numberRegexString) HexadecimalRegex = regexp.MustCompile(hexadecimalRegexString) HexcolorRegex = regexp.MustCompile(hexcolorRegexString) RgbRegex = regexp.MustCompile(rgbRegexString) RgbaRegex = regexp.MustCompile(rgbaRegexString) HslRegex = regexp.MustCompile(hslRegexString) HslaRegex = regexp.MustCompile(hslaRegexString) E164Regex = regexp.MustCompile(e164RegexString) EmailRegex = regexp.MustCompile(emailRegexString) Base64Regex = regexp.MustCompile(base64RegexString) Base64URLRegex = regexp.MustCompile(base64URLRegexString) ISBN10Regex = regexp.MustCompile(iSBN10RegexString) ISBN13Regex = regexp.MustCompile(iSBN13RegexString) UUID3Regex = regexp.MustCompile(uUID3RegexString) UUID4Regex = regexp.MustCompile(uUID4RegexString) UUID5Regex = regexp.MustCompile(uUID5RegexString) UUIDRegex = regexp.MustCompile(uUIDRegexString) UUID3RFC4122Regex = regexp.MustCompile(uUID3RFC4122RegexString) UUID4RFC4122Regex = regexp.MustCompile(uUID4RFC4122RegexString) UUID5RFC4122Regex = regexp.MustCompile(uUID5RFC4122RegexString) UUIDRFC4122Regex = regexp.MustCompile(uUIDRFC4122RegexString) ASCIIRegex = regexp.MustCompile(aSCIIRegexString) PrintableASCIIRegex = regexp.MustCompile(printableASCIIRegexString) MultibyteRegex = regexp.MustCompile(multibyteRegexString) DataURIRegex = regexp.MustCompile(dataURIRegexString) LatitudeRegex = regexp.MustCompile(latitudeRegexString) LongitudeRegex = regexp.MustCompile(longitudeRegexString) SSNRegex = regexp.MustCompile(sSNRegexString) HostnameRegexRFC952 = regexp.MustCompile(hostnameRegexStringRFC952) HostnameRegexRFC1123 = regexp.MustCompile(hostnameRegexStringRFC1123) FqdnRegexRFC1123 = regexp.MustCompile(fqdnRegexStringRFC1123) BtcAddressRegex = regexp.MustCompile(btcAddressRegexString) BtcUpperAddressRegexBech32 = regexp.MustCompile(btcAddressUpperRegexStringBech32) BtcLowerAddressRegexBech32 = regexp.MustCompile(btcAddressLowerRegexStringBech32) EthAddressRegex = regexp.MustCompile(ethAddressRegexString) EthaddressRegexUpper = regexp.MustCompile(ethAddressUpperRegexString) EthAddressRegexLower = regexp.MustCompile(ethAddressLowerRegexString) URLEncodedRegex = regexp.MustCompile(uRLEncodedRegexString) HTMLEncodedRegex = regexp.MustCompile(hTMLEncodedRegexString) HTMLRegex = regexp.MustCompile(hTMLRegexString) )
View Source
var (
ErrFunctionAlreadyRegistered = errors.New("function already registered")
)
Functions ¶
func MustRegisterValidation ¶
func MustRegisterValidation(name string, r *ValidationRegistration)
func RegisterValidation ¶
func RegisterValidation(name string, r *ValidationRegistration) error
Types ¶
type CustomValidation ¶
type CustomValidation interface {
CustomValidate() error
}
CustomValidation is used to implement custom validations that are not directly supported by the library.
The generate `Validate` method will call the `CustomValidation` automatically, if the model implements it.
type FieldContext ¶
FieldContext is the information that is passed to the validation function `Func`.
type FieldData ¶
type FieldData struct {
// Field *myasthurts.Field
Name string
Identifier string
IsPointer bool
IsArray bool
IsNumeric bool
IsBoolean bool
IsString bool
Validations []*ValidationPair
}
func NewFieldData ¶
func NewFieldData(field *myasthurts.Field) *FieldData
type FieldError ¶
type FieldError struct {
Field string
Rule string
Value interface{}
// contains filtered or unexported fields
}
func NewFieldError ¶
func NewFieldError(err error, rule, field string, value interface{}) *FieldError
func (*FieldError) Error ¶
func (err *FieldError) Error() string
func (*FieldError) Unwrap ¶
func (err *FieldError) Unwrap() error
type Func ¶
type Func func(fieldContext FieldContext) bool
Func accepts a FieldContext struct for all validation needs. The return value should be true when validation succeeds.
type FuncCtx ¶
type FuncCtx func(ctx context.Context, fieldContext FieldContext) bool
FuncCtx accepts a context.Context and FieldContext interface for all validation needs. The return value should be true when validation succeeds.
type ImportData ¶
type StructData ¶
type StructData struct {
Struct *myasthurts.Struct
Fields []*FieldData
}
type Validable ¶
type Validable interface {
// Validate validates the struct
Validate() error
}
Validable abstracts the behavior of a struct that can be validated.
type ValidateValidationField ¶
type ValidateValidationField = func(s *StructData, field *FieldData, validation *ValidationData) error
type ValidationData ¶
type ValidationData struct {
Params []string
}
type ValidationErrors ¶
type ValidationErrors []*FieldError
func (ValidationErrors) Error ¶
func (err ValidationErrors) Error() string
type ValidationGenerationFunc ¶
type ValidationGenerationFunc = func(w *quicktemplate.Writer, s *StructData, field *FieldData, validation *ValidationData)
type ValidationPair ¶
type ValidationPair struct {
Validation *ValidationRegistration
Data *ValidationData
}
type ValidationRegistration ¶
type ValidationRegistration struct {
Func ValidationGenerationFunc
Imports []*ImportData
ValidateField ValidateValidationField
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cli
|
|
|
validator-gen
command
|
|
|
Code generated by validator-gen.
|
Code generated by validator-gen. |
Click to show internal directories.
Click to hide internal directories.