package validator import "github.com/go-playground/validator/v10" type ErrorResponse struct { FailedField string Tag string Value string } var validate = validator.New() func ValidateRequest(model interface{}) []*ErrorResponse { var errors []*ErrorResponse err := validate.Struct(model) if err != nil { for _, err := range err.(validator.ValidationErrors) { var element ErrorResponse element.FailedField = err.StructNamespace() element.Tag = err.Tag() element.Value = err.Param() errors = append(errors, &element) } } return errors }