Documentation ¶
Overview ¶
commonserrors package was created with intent to standardizing a way to execute the data structure validation processo that returns the validation erros every in the same way and in the same language.
by convention, the english language was choosen as a default and unique language. Case your code want to use a diferente language the better for you is do not use this library and and choose to use the standard form of the go-playground/validator library
The first step to use this package is to get it through the command below, then you will be able to import it in your code.
go get github.com/finacore/commons-validation
To avoid the conflicts between packages during the imnport phase, is strongly recommended select other name for this package in the moment of import like shown below:
import ( commonsvalidation "github.com/finacore/commons-validation" )
Once imported you can use the package as you prefer. So read the function and methods documentation to know how to use this packagage.
commonserrors package was created with intent to standardizing a way to execute the data structure validation processo that returns the validation erros every in the same way and in the same language.
by convention, the english language was choosen as a default and unique language. Case your code want to use a diferente language the better for you is do not use this library and and choose to use the standard form of the go-playground/validator library
The first step to use this package is to get it through the command below, then you will be able to import it in your code.
go get github.com/finacore/commons-validation
To avoid the conflicts between packages during the imnport phase, is strongly recommended select other name for this package in the moment of import like shown below:
import ( commonsvalidation "github.com/finacore/commons-validation" )
Once imported you can use the package as you prefer. So read the function and methods documentation to know how to use this packagage.
commonserrors package was created with intent to standardizing a way to execute the data structure validation processo that returns the validation erros every in the same way and in the same language.
by convention, the english language was choosen as a default and unique language. Case your code want to use a diferente language the better for you is do not use this library and and choose to use the standard form of the go-playground/validator library
The first step to use this package is to get it through the command below, then you will be able to import it in your code.
go get github.com/finacore/commons-validation
To avoid the conflicts between packages during the imnport phase, is strongly recommended select other name for this package in the moment of import like shown below:
import ( commonsvalidation "github.com/finacore/commons-validation" )
Once imported you can use the package as you prefer. So read the function and methods documentation to know how to use this packagage.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CustomValidator ¶ added in v1.1.0
type CustomValidator struct {
// contains filtered or unexported fields
}
CustomValidator data structure that store the validator.Validate and ut.Translator objects, as well the list o of commonserrors.validationErros populated after execution of Model method.
This data structure is not public to avoid the programers create it directly, this way to create a instance of this struct is necessary call the New function.
func New ¶
func New() *CustomValidator
New has the responsibility to create and instantiate the data structure that able to create a pre convfigured validator that translate the errors to human english language.
Usage:
cv := commonsvalidation.New()
func (*CustomValidator) Model ¶ added in v1.1.0
func (cv *CustomValidator) Model(model interface{}) ValidatorResult
Model validator execute the validation of model passed by parameter. Once this method is called, the result is stored internaly in the data structure
Usage:
cv := commonsvalidation.New() vr := cv.Model(yourModel)
type ValidatorResult ¶ added in v1.2.0
type ValidatorResult []commonsErrors.ValidationError
ValidatorResult is da data structure that has a responsibility to store the response of the validation process. This data structure implements some methods to help get access to the data
func (ValidatorResult) Count ¶ added in v1.2.0
func (vr ValidatorResult) Count() int
Count returns how many validation errors was produced by the validation process execution
Usage:
cv := commonsvalidation.New() vr := cv.Model(yourModel) numErrors := vr.Count()
func (ValidatorResult) Errors ¶ added in v1.2.0
func (vr ValidatorResult) Errors() []commonsErrors.ValidationError
Errors return the commonserrors.ValidationError array containing all errors returned by the execution of validation process
Usage:
cv := commonsvalidation.New() vr := cv.Model(yourModel) errs := vr.Errors()
func (ValidatorResult) HasError ¶ added in v1.2.0
func (vr ValidatorResult) HasError() bool
HasError provivide a simple way to check if the validatorResponse produce or not errors
Usage:
cv := commonsvalidation.New() vr := cv.Model(yourModel) hasError := vr.HasError()