2022-11-30 16:18:01 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2023-02-20 10:56:30 +01:00
|
|
|
"github.com/go-playground/validator/v10"
|
2022-11-30 16:18:01 +01:00
|
|
|
)
|
|
|
|
|
2023-02-15 08:05:43 +01:00
|
|
|
type Validator struct {
|
|
|
|
ValidatorProvider *validator.Validate
|
2022-11-30 16:18:01 +01:00
|
|
|
}
|
|
|
|
|
2023-02-15 08:05:43 +01:00
|
|
|
func (v *Validator) Validate(i interface{}) error {
|
|
|
|
if err := v.ValidatorProvider.Struct(i); err != nil {
|
2023-02-24 17:46:46 +01:00
|
|
|
if _, ok := err.(validator.ValidationErrors); ok {
|
|
|
|
return NewBadRequestError(err.(validator.ValidationErrors).Error())
|
|
|
|
}
|
2022-11-30 16:18:01 +01:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|