v9.0.0
This commit is contained in:
54
internal/validators/helper.go
Normal file
54
internal/validators/helper.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package validators
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"repository.basistech.ru/BASIS/dynamix-golang-sdk/v9/internal/multierror"
|
||||
|
||||
"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))
|
||||
}
|
||||
|
||||
func ValidationErrors(fes []validator.FieldError) error {
|
||||
errs := make([]error, 0, len(fes))
|
||||
for _, fe := range fes {
|
||||
errs = append(errs, ValidationError(fe))
|
||||
}
|
||||
return multierror.Join(errs...)
|
||||
}
|
||||
|
||||
//nolint:errorlint
|
||||
func GetErrors(err error) validator.ValidationErrors {
|
||||
return err.(validator.ValidationErrors)
|
||||
}
|
||||
|
||||
func IsInSlice(str string, target []string) bool {
|
||||
for _, v := range target {
|
||||
if v == str {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func IsSubSlice(source []string, target []string) bool {
|
||||
for _, s := range source {
|
||||
if !IsInSlice(s, target) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
Reference in New Issue
Block a user