cic-custodial/internal/api/validator.go

23 lines
404 B
Go
Raw Normal View History

package api
import (
"net/http"
"github.com/go-playground/validator"
"github.com/labstack/echo/v4"
)
2023-02-02 13:29:43 +01:00
type Validator struct {
ValidatorProvider *validator.Validate
}
2023-02-02 13:29:43 +01:00
func (v *Validator) Validate(i interface{}) error {
if err := v.ValidatorProvider.Struct(i); err != nil {
2023-02-12 14:53:53 +01:00
return echo.NewHTTPError(http.StatusBadRequest, ErrResp{
2023-02-02 13:29:43 +01:00
Ok: false,
Code: VALIDATION_ERROR,
})
}
return nil
}