Documentation
ΒΆ
Index ΒΆ
- func GetValidationFromStructField(tagType string, fieldValue reflect.Value, fieldType reflect.StructField) (*model.Validation, error)
- func GetValidationsFromStruct(in any, tagType string) ([]model.Validation, error)
- func UnmapAndValidate(request *http.Request, structToUpdate any, tagType ...string) error
- func UnmapOrUnmarshalAndValidate(request *http.Request, structToUpdate any, tagType ...string) error
- func UnmapOrUnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
- func UnmapOrUnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, ...) error
- func UnmapValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
- func UnmapValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, ...) error
- func UnmarshalAndValidate(request *http.Request, v any, tagType ...string) error
- func UnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
- func UnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, ...) error
- func Validate(v any, tagType ...string) error
- func ValidateAndUpdate(jsonInput map[string]any, structToUpdate any, tagType ...string) error
- func ValidateAndUpdateWithValidation(jsonInput map[string]any, mapToUpdate *map[string]any, ...) error
- func ValidateWithValidation(jsonInput map[string]any, validations []model.Validation) (map[string]any, error)
- type ValidationFunc
- type Validator
- func (r *Validator) AddValidationFunc(fn ValidationFunc, name string)
- func (r *Validator) RunValidatorsOnConditionGroup(input any, astValue *model.AstValue) error
- func (r *Validator) UnmapAndValidate(request *http.Request, structToValidate any, tagType ...string) error
- func (r *Validator) UnmapOrUnmarshalAndValidate(request *http.Request, structToUpdate any, tagType ...string) error
- func (r *Validator) UnmapOrUnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
- func (r *Validator) UnmapOrUnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, ...) error
- func (r *Validator) UnmapValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
- func (r *Validator) UnmapValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, ...) error
- func (r *Validator) UnmarshalAndValidate(request *http.Request, structToValidate any, tagType ...string) error
- func (r *Validator) UnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
- func (r *Validator) UnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, ...) error
- func (r *Validator) Validate(v any, tagType ...string) error
- func (r *Validator) ValidateAndUpdate(jsonInput map[string]any, structToUpdate any, tagType ...string) error
- func (r *Validator) ValidateAndUpdateWithValidation(jsonInput map[string]any, mapToUpdate *map[string]any, ...) error
- func (r *Validator) ValidateValueWithParser(input any, validation *model.Validation) error
- func (r *Validator) ValidateWithValidation(jsonInput map[string]any, validations []model.Validation) (map[string]any, error)
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
func GetValidationFromStructField ΒΆ added in v0.20.0
func GetValidationFromStructField(tagType string, fieldValue reflect.Value, fieldType reflect.StructField) (*model.Validation, error)
GetValidationFromStructField extracts validation rules from a struct field based on the provided tag type. It checks the field's tag for the specified tag type and constructs a Validation object. If no json tag is found, it uses the field name as the key.
func GetValidationsFromStruct ΒΆ added in v0.20.0
func GetValidationsFromStruct(in any, tagType string) ([]model.Validation, error)
GetValidationsFromStruct extracts validation rules from a struct based on the provided tag type. It iterates over the struct fields, checks for the specified tag type, and constructs Validation.
func UnmapAndValidate ΒΆ added in v0.5.0
UnmapAndValidate is the wrapper function for the UnmapAndValidate method of the Validator struct. More details can be found in the UnmapAndValidate method.
func UnmapOrUnmarshalAndValidate ΒΆ added in v0.5.0
func UnmapOrUnmarshalAndValidate(request *http.Request, structToUpdate any, tagType ...string) error
UnmapOrUnmarshalAndValidate is the wrapper function for the UnmapOrUnmarshalAndValidate method of the Validator struct. More details can be found in the UnmapOrUnmarshalAndValidate method.
func UnmapOrUnmarshalValidateAndUpdate ΒΆ added in v0.5.0
func UnmapOrUnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
UnmapOrUnmarshalValidateAndUpdate is the wrapper function for the UnmapOrUnmarshalValidateAndUpdate method of the Validator struct. More details can be found in the UnmapOrUnmarshalValidateAndUpdate method.
func UnmapOrUnmarshalValidateAndUpdateWithValidation ΒΆ added in v0.5.0
func UnmapOrUnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, validations []model.Validation) error
UnmapOrUnmarshalValidateAndUpdateWithValidation is the wrapper function for the UnmapOrUnmarshalValidateAndUpdateWithValidation method of the Validator struct. More details can be found in the UnmapOrUnmarshalValidateAndUpdateWithValidation method.
func UnmapValidateAndUpdate ΒΆ added in v0.2.1
UnmapValidateAndUpdate is the wrapper function for the UnmapValidateAndUpdate method of the Validator struct. More details can be found in the UnmapValidateAndUpdate method.
func UnmapValidateAndUpdateWithValidation ΒΆ added in v0.2.8
func UnmapValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, validations []model.Validation) error
UnmapValidateAndUpdateWithValidation is the wrapper function for the UnmapValidateAndUpdateWithValidation method of the Validator struct. More details can be found in the UnmapValidateAndUpdateWithValidation method.
func UnmarshalAndValidate ΒΆ
UnmarshalAndValidate is the wrapper function for the UnmarshalAndValidate method of the Validator struct. More details can be found in the UnmarshalAndValidate method.
func UnmarshalValidateAndUpdate ΒΆ
UnmarshalValidateAndUpdate is the wrapper function for the UnmarshalValidateAndUpdate method of the Validator struct. More details can be found in the UnmarshalValidateAndUpdate method.
func UnmarshalValidateAndUpdateWithValidation ΒΆ added in v0.2.8
func UnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, validations []model.Validation) error
UnmarshalValidateAndUpdateWithValidation is the wrapper function for the UnmarshalValidateAndUpdateWithValidation method of the Validator struct. More details can be found in the UnmarshalValidateAndUpdateWithValidation method.
func Validate ΒΆ
Validate is the wrapper function for the Validate method of the Validator struct. More details can be found in the Validate method.
func ValidateAndUpdate ΒΆ
ValidateAndUpdate is the wrapper function for the ValidateAndUpdate method of the Validator struct. More details can be found in the ValidateAndUpdate method.
func ValidateAndUpdateWithValidation ΒΆ added in v0.2.8
func ValidateAndUpdateWithValidation(jsonInput map[string]any, mapToUpdate *map[string]any, validations []model.Validation) error
ValidateAndUpdateWithValidation is the wrapper function for the ValidateAndUpdateWithValidation method of the Validator struct. More details can be found in the ValidateAndUpdateWithValidation method.
func ValidateWithValidation ΒΆ added in v0.4.0
func ValidateWithValidation(jsonInput map[string]any, validations []model.Validation) (map[string]any, error)
ValidateWithValidation is the wrapper function for the ValidateWithValidation method of the Validator struct. More details can be found in the ValidateWithValidation method.
Types ΒΆ
type ValidationFunc ΒΆ added in v0.5.0
type Validator ΒΆ added in v0.5.0
type Validator struct {
ValidationFuncs map[string]ValidationFunc
}
Validator is the main struct for validation.
func NewValidator ΒΆ added in v0.5.0
func NewValidator() *Validator
NewValidator creates a new Validator instance with an empty validation functions map.
func (*Validator) AddValidationFunc ΒΆ added in v0.5.0
func (r *Validator) AddValidationFunc(fn ValidationFunc, name string)
AddValidationFunc adds a custom validation function to the Validator. The function can be used in validation requirements with the name provided (`fun<name>`).
func (*Validator) RunValidatorsOnConditionGroup ΒΆ added in v0.5.0
RunFuncOnConditionGroup runs the function [f] on each condition in the [astValue]. If the condition is a group, it recursively calls itself on the group. If the condition is a condition, it calls the function [f] with the input and the condition. If the operator is AND, it returns an error if any condition fails. If the operator is OR, it collects all errors and returns them if all conditions fail.
func (*Validator) UnmapAndValidate ΒΆ added in v0.5.0
func (r *Validator) UnmapAndValidate(request *http.Request, structToValidate any, tagType ...string) error
UnmapAndValidate unmaps the url.Values from the request.Form into a JsonMap and puts it into the given struct. It validates the struct by the given tagType. It returns an error if the unmapping or validation fails.
It is actually doing the same as UnmapValidateAndUpdate, but in another order. It does directly update the struct and validates afterwards. Normally you would either only use Validate or use UnmapValidateAndUpdate for early return on error.
func (*Validator) UnmapOrUnmarshalAndValidate ΒΆ added in v0.5.0
func (r *Validator) UnmapOrUnmarshalAndValidate(request *http.Request, structToUpdate any, tagType ...string) error
UnmapOrUnmarshalAndValidate unmarshals given json ([]byte) or given url.Values (from request.Form), validates them and updates the given struct. It returns an error if the unmapping or validation fails.
It is actually doing the same as UnmapOrUnmarshalValidateAndUpdate, but in another order. It does directly update the struct and validates afterwards. Normally you would either only use Validate or use UnmapOrUnmarshalValidateAndUpdate for early return on error.
func (*Validator) UnmapOrUnmarshalValidateAndUpdate ΒΆ added in v0.5.0
func (r *Validator) UnmapOrUnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
UnmapOrUnmarshalValidateAndUpdate unmarshals given json ([]byte) or given url.Values (from request.Form), validates them and updates the given struct. It returns an error if the unmapping, validation or update fails.
For more information look at ValidateAndUpdate.
func (*Validator) UnmapOrUnmarshalValidateAndUpdateWithValidation ΒΆ added in v0.5.0
func (r *Validator) UnmapOrUnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, validations []model.Validation) error
UnmapOrUnmarshalValidateAndUpdateWithValidation unmarshals given json ([]byte) or given url.Values (from request.Form). It validates the map with the given validations and updates the given map. It returns an error if the unmapping, validation or update fails.
func (*Validator) UnmapValidateAndUpdate ΒΆ added in v0.5.0
func (r *Validator) UnmapValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
UnmapValidateAndUpdate unmaps given url.Values into pointer jsonMap. It returns an error if the unmapping, validation or update fails.
For more information look at ValidateAndUpdate.
func (*Validator) UnmapValidateAndUpdateWithValidation ΒΆ added in v0.5.0
func (r *Validator) UnmapValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, validations []model.Validation) error
UnmapValidateAndUpdateWithValidation unmaps given url.Values into pointer jsonMap. It validates the map by the given validations and updates it. It returns an error if the unmapping, validation or update fails.
func (*Validator) UnmarshalAndValidate ΒΆ added in v0.5.0
func (r *Validator) UnmarshalAndValidate(request *http.Request, structToValidate any, tagType ...string) error
UnmarshalAndValidate unmarshals given json ([]byte) into pointer v. It validates the struct by the given tagType. It returns an error if the unmarshaling or validation fails.
It is actually doing the same as UnmarshalValidateAndUpdate, but in another order. It does directly update the struct and validates afterwards. Normally you would either only use Validate or use UnmarshalValidateAndUpdate for early return on error.
func (*Validator) UnmarshalValidateAndUpdate ΒΆ added in v0.5.0
func (r *Validator) UnmarshalValidateAndUpdate(request *http.Request, structToUpdate any, tagType ...string) error
UnmarshalValidateAndUpdate unmarshals given json ([]byte) into pointer v. It returns an error if the unmapping, validation or update fails.
For more information look at ValidateAndUpdate.
func (*Validator) UnmarshalValidateAndUpdateWithValidation ΒΆ added in v0.5.0
func (r *Validator) UnmarshalValidateAndUpdateWithValidation(request *http.Request, mapToUpdate *map[string]any, validations []model.Validation) error
UnmarshalValidateAndUpdateWithValidation unmarshals given json ([]byte) into pointer mapToUpdate. It validates the map by the given validations and updates it. It returns an error if the unmarshaling, validation or update fails.
func (*Validator) Validate ΒΆ added in v0.5.0
Validate validates a given struct by the given tagType. It checks if the keys are in the struct and validates the values. It returns an error if the validation fails.
func (*Validator) ValidateAndUpdate ΒΆ added in v0.5.0
func (r *Validator) ValidateAndUpdate(jsonInput map[string]any, structToUpdate any, tagType ...string) error
ValidateAndUpdate validates a given JsonMap by the given validations and updates the struct. It checks if the keys are in the map, validates the values and updates the struct if the validation passes. It returns an error if the validation fails or if the struct cannot be updated.
func (*Validator) ValidateAndUpdateWithValidation ΒΆ added in v0.5.0
func (r *Validator) ValidateAndUpdateWithValidation(jsonInput map[string]any, mapToUpdate *map[string]any, validations []model.Validation) error
ValidateAndUpdateWithValidation validates a given JsonMap by the given validations and updates the map. It checks if the keys are in the map, validates the values and updates the map if the validation passes. It returns an error if the validation fails or if the map cannot be updated.
func (*Validator) ValidateValueWithParser ΒΆ added in v0.5.0
func (r *Validator) ValidateValueWithParser(input any, validation *model.Validation) error
ValidateValueWithParser validates a value against a given validation using the parser. It parses the validation requirement and runs the validation function on the input value.
It returns an error if the validation fails.
func (*Validator) ValidateWithValidation ΒΆ added in v0.5.0
func (r *Validator) ValidateWithValidation(jsonInput map[string]any, validations []model.Validation) (map[string]any, error)
ValidateWithValidation validates a given JsonMap by the given validations. This is the main validation function that is used for all validation. It checks if the keys are in the map, validates the values and returns a new JsonMap.
If a validation has groups, it checks if the values are valid for the groups. If a validation has a key that is already in the map, it returns an error.
It returns a new JsonMap with the validated values or an error if the validation fails.