Ejemplo n.º 1
0
func (c Validator) IsModelValid(climb interface{}, ctx validation.Context) error {
	m := climb.(Model)
	e := boom.NewError("Validation error. Please fix the errors before continuing.")

	if b := govalidator.InRange(float64(m.Latitude), -90, 90); !b {
		e.AddError("Latitude", fmt.Sprintf("%v is outside range [-90, 90]", m.Latitude))
	}

	if b := govalidator.InRange(float64(m.Longitude), -180, 180); !b {
		e.AddError("Longitude", fmt.Sprintf("%v is outside range [-180, 180]", m.Longitude))
	}

	if len(e.Errors) == 0 {
		return nil
	} else {
		return e
	}
}
Ejemplo n.º 2
0
func (c Validator) IsModelValid(climb interface{}, ctx validation.Context) error {
	m := climb.(Model)
	e := boom.NewError("Validation error. Please fix the errors before continuing.")

	if b := govalidator.StringLength(m.Name, "0", "15"); !b {
		e.AddError("Name", "cannot exceed 15 characters")
	}

	if b := govalidator.InRange(float64(m.Rating), 0, 16); !b {
		e.AddError("Rating", fmt.Sprintf("%v is outside range [0, 16]"))
	}

	if b := govalidator.StringLength(m.Description, "0", "255"); !b {
		e.AddError("Description", fmt.Sprintf("cannot exceed 255 characters"))
	}

	if len(e.Errors) == 0 {
		return nil
	} else {
		return e
	}
}
Ejemplo n.º 3
0
//Public methods
func (s *service) InRange(value, left, right float64) bool   { return gov.InRange(value, left, right) }