cic-custodial/internal/api/validator.go

23 lines
404 B
Go

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