예제 #1
0
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
	}
}
예제 #2
0
func (i IsFloatChecker) IsFormat(data string) bool {
	return govalidator.IsFloat(data)
}
예제 #3
0
func (s *service) IsFloat(str string) bool                   { return gov.IsFloat(str) }