Documentation
¶
Overview ¶
blu is struct value validation based on tags.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ErrorDuplicatedRule ¶
type ErrorDuplicatedRule struct {
RuleName string
}
ErrorDuplicatedRule an error type for attempting register new rule.
func (*ErrorDuplicatedRule) Error ¶
func (e *ErrorDuplicatedRule) Error() string
Error returns an error message indicating that a rule with the same name already exists.
type ErrorInvalidInput ¶
InvalidaInputError an error type indicating an issue with input validation.
func (*ErrorInvalidInput) Error ¶
func (e *ErrorInvalidInput) Error() string
Error return for invalid input (non-struct).
type ErrorUnexportedField ¶
type ErrorUnexportedField struct {
Field string
}
ErrorUnexportedField an error type for attempting to validate an unexported field.
func (*ErrorUnexportedField) Error ¶
func (e *ErrorUnexportedField) Error() string
Error returns an error message indicating unexported field (lowercase).
type Rule ¶
type Rule interface { // Name return the name of the validation rule. Name() string // Validate performs validation on the field value with the provided parameters. // It returns an error if the validation fails; otherwise, it returns nil. Validate(field, value, param string) error }
Rule represents a validation rule for validating field values.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator contains the validation rules.
func (*Validator) RegisterRule ¶
RegisterRule registers a new rule into the validator. It returns an error if the rule name is already registered.
func (*Validator) Validate ¶
Validate validates the field value of the given struct based on tags. It returns an error if the input is not a struct. It returns an error if struct not exportable. If there are validation errors for the struct fields, it return a joined error that contains all the validation errors. It return nil if validation success.
func (*Validator) ValidateField ¶
ValidateField validates the field value based on the provided tags. It returns a joined error that contains all validation errors of the field.