You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
579 B
Go
27 lines
579 B
Go
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
|
|
}
|