package app import ( "strings" "github.com/gin-gonic/gin" ) type ValidError struct { Message string } type ValidErrors []*ValidError func (v *ValidError) Error() string { return v.Message } func (v ValidErrors) Error() string { return strings.Join(v.Errors(), ",") } func (v ValidErrors) Errors() []string { var errs []string for _, err := range v { errs = append(errs, err.Error()) } return errs } func BindAndValid(c *gin.Context, v interface{}) (bool, ValidErrors) { var errs ValidErrors err := c.ShouldBind(v) if err != nil { errs = append(errs, &ValidError{ Message: err.Error(), }) return false, errs } return true, nil }