You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
657 B
36 lines
657 B
package validators
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/go-playground/validator/v10"
|
|
)
|
|
|
|
func ValidateRequest(req interface{}) error {
|
|
validate := getDecortValidator()
|
|
return validate.Struct(req)
|
|
}
|
|
|
|
func ValidateConfig(cfg interface{}) error {
|
|
validate := getDecortValidator()
|
|
return validate.Struct(cfg)
|
|
}
|
|
|
|
func ValidationError(fe validator.FieldError) error {
|
|
return errors.New(errorMessage(fe))
|
|
}
|
|
|
|
//nolint:errorlint
|
|
func GetErrors(err error) validator.ValidationErrors {
|
|
return err.(validator.ValidationErrors)
|
|
}
|
|
|
|
func StringInSlice(str string, target []string) bool {
|
|
for _, v := range target {
|
|
if v == str {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|