Documentation ¶
Index ¶
- func AddConstraint(name string, constraint Constraint)
- func AddParser(extension string, parser Parser)
- func ColorHexConstraint(ctx *ValidationContext) error
- func EmailConstraint(ctx *ValidationContext) error
- func ISO3166Constraint(ctx *ValidationContext) error
- func ISO639Constraint(ctx *ValidationContext) error
- func LengthConstraint(ctx *ValidationContext) error
- func LoadFiles(patterns ...string) error
- func MaxConstraint(ctx *ValidationContext) error
- func MinConstraint(ctx *ValidationContext) error
- func RegexConstraint(ctx *ValidationContext) error
- func RequiredConstraint(ctx *ValidationContext) error
- func StringConstraint(ctx *ValidationContext) error
- func StructConstraint(ctx *ValidationContext) error
- func UUIDConstraint(ctx *ValidationContext) error
- type Constraint
- type ConstraintArgs
- type ConstraintMetadata
- type CustomConstraint
- type ErrorTranslator
- type FieldMetadata
- type Parser
- type StructMetadata
- type ValidationContext
- func (ctx *ValidationContext) Arg() interface{}
- func (ctx *ValidationContext) BuildViolation(error string, parameters map[string]interface{}) *violationBuilder
- func (ctx *ValidationContext) Ctx() context.Context
- func (ctx *ValidationContext) Path() string
- func (ctx *ValidationContext) Root() interface{}
- func (ctx *ValidationContext) Subject() interface{}
- func (ctx *ValidationContext) Value() interface{}
- func (ctx *ValidationContext) ViolationList() ViolationList
- func (ctx *ValidationContext) WithArg(arg interface{}) *ValidationContext
- func (ctx *ValidationContext) WithValue(value interface{}) *ValidationContext
- type Validator
- func (validator *Validator) AddConstraint(name string, constraint Constraint)
- func (validator *Validator) AddParser(extension string, parser Parser)
- func (validator *Validator) LoadFiles(patterns ...string) error
- func (validator *Validator) Validate(subject interface{}) (bool, ViolationList, error)
- func (validator *Validator) ValidateWithContext(ctx context.Context, subject interface{}) (isValid bool, violations ViolationList, err error)
- type Violation
- type ViolationList
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConstraint ¶
func AddConstraint(name string, constraint Constraint)
func ColorHexConstraint ¶
func ColorHexConstraint(ctx *ValidationContext) error
func EmailConstraint ¶
func EmailConstraint(ctx *ValidationContext) error
func ISO3166Constraint ¶
func ISO3166Constraint(ctx *ValidationContext) error
func ISO639Constraint ¶
func ISO639Constraint(ctx *ValidationContext) error
func LengthConstraint ¶
func LengthConstraint(ctx *ValidationContext) error
func MaxConstraint ¶
func MaxConstraint(ctx *ValidationContext) error
func MinConstraint ¶
func MinConstraint(ctx *ValidationContext) error
func RegexConstraint ¶
func RegexConstraint(ctx *ValidationContext) error
func RequiredConstraint ¶
func RequiredConstraint(ctx *ValidationContext) error
func StringConstraint ¶
func StringConstraint(ctx *ValidationContext) error
func StructConstraint ¶
func StructConstraint(ctx *ValidationContext) error
func UUIDConstraint ¶
func UUIDConstraint(ctx *ValidationContext) error
Types ¶
type Constraint ¶
type Constraint func(ctx *ValidationContext) error
type ConstraintArgs ¶
type ConstraintArgs struct { Root interface{} Subject interface{} Value interface{} Arg interface{} }
type ConstraintMetadata ¶
type ConstraintMetadata struct { Tag string Constraint Constraint Arg interface{} }
type CustomConstraint ¶
type CustomConstraint struct { Name string Constraint Constraint }
func NewCustomConstraint ¶
func NewCustomConstraint(name string, constraint Constraint) CustomConstraint
type ErrorTranslator ¶
var TranslateError ErrorTranslator = func(key string, parameters map[string]interface{}) string {
return key
}
type FieldMetadata ¶
type FieldMetadata struct { FieldName string Constraints []*ConstraintMetadata }
type Parser ¶
type Parser func(config string) ([]*StructMetadata, error)
type StructMetadata ¶
type StructMetadata struct { StructName string Fields map[string]*FieldMetadata }
type ValidationContext ¶
type ValidationContext struct {
// contains filtered or unexported fields
}
func (*ValidationContext) Arg ¶
func (ctx *ValidationContext) Arg() interface{}
func (*ValidationContext) BuildViolation ¶
func (ctx *ValidationContext) BuildViolation(error string, parameters map[string]interface{}) *violationBuilder
func (*ValidationContext) Ctx ¶
func (ctx *ValidationContext) Ctx() context.Context
func (*ValidationContext) Path ¶
func (ctx *ValidationContext) Path() string
func (*ValidationContext) Root ¶
func (ctx *ValidationContext) Root() interface{}
func (*ValidationContext) Subject ¶
func (ctx *ValidationContext) Subject() interface{}
func (*ValidationContext) Value ¶
func (ctx *ValidationContext) Value() interface{}
func (*ValidationContext) ViolationList ¶
func (ctx *ValidationContext) ViolationList() ViolationList
func (*ValidationContext) WithArg ¶
func (ctx *ValidationContext) WithArg(arg interface{}) *ValidationContext
func (*ValidationContext) WithValue ¶
func (ctx *ValidationContext) WithValue(value interface{}) *ValidationContext
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
func NewValidator ¶
func NewValidator(customConstraints ...CustomConstraint) *Validator
func (*Validator) AddConstraint ¶
func (validator *Validator) AddConstraint(name string, constraint Constraint)
func (*Validator) Validate ¶
func (validator *Validator) Validate(subject interface{}) (bool, ViolationList, error)
func (*Validator) ValidateWithContext ¶
type ViolationList ¶
type ViolationList []*Violation
func Validate ¶
func Validate(subject interface{}) (bool, ViolationList, error)
func ValidateWithContext ¶
func ValidateWithContext(ctx context.Context, subject interface{}) (bool, ViolationList, error)
func (ViolationList) String ¶
func (violations ViolationList) String() string
Source Files ¶
Click to show internal directories.
Click to hide internal directories.