func (c Validator) IsCriteriaValid(d decode.Criteria, ctx validation.Context) error { e := boom.NewError("Query error. Please fix the errors before continuing.") for _, filter := range d.Filters { switch filter.Field { case "Bounds": if len(strings.Split(filter.Value, ",")) != 4 { e.AddError("Bounds", "must contain four coordinates") } case "After": if b := govalidator.IsInt(filter.Value); !b { e.AddError("After", "must be integer") } if len(d.Sorters) == 0 { e.AddError("After", "must have a sort param") } case "Before": if b := govalidator.IsInt(filter.Value); !b { e.AddError("Before", "must be integer") } if len(d.Sorters) == 0 { e.AddError("Before", "must have a sort param") } } } if len(e.Errors) == 0 { return nil } else { return e } }
func (c Validator) IsCriteriaValid(d decode.Criteria, ctx validation.Context) error { e := boom.NewError("Query error. Please fix the errors before continuing.") for _, filter := range d.Filters { switch filter.Field { case "After": if b := govalidator.IsInt(filter.Value); !b { e.AddError("After", "must be integer") } if len(d.Sorters) == 0 { e.AddError("After", "must have a sort param") } case "Before": if b := govalidator.IsInt(filter.Value); !b { e.AddError("Before", "must be integer") } if len(d.Sorters) == 0 { e.AddError("Before", "must have a sort param") } case "Latitude": values := strings.Split(filter.Value, ",") for _, value := range values { if b := govalidator.IsFloat(value); !b { e.AddError("Latitude", "must be numeric") } } case "Longitude": values := strings.Split(filter.Value, ",") for _, value := range values { if b := govalidator.IsFloat(value); !b { e.AddError("Longitude", "must be numeric") } } } } if len(e.Errors) == 0 { return nil } else { return e } }
func (i IsIntChecker) IsFormat(data string) bool { return govalidator.IsInt(data) }
func (s *service) IsInt(str string) bool { return gov.IsInt(str) }