func (c *ServicesReq) run() (interface{}, error) {
	var err error
	fail := func(err string) (*ServicesResp, error) {
		response := ServicesResp{Message: fmt.Sprintf("Failed - %s", err)}
		return &response, fmt.Errorf("%s", err)
	}

	switch {
	case c.LatitudeV > 24.0 && c.LongitudeV >= -180.0 && c.LongitudeV <= -66.0:
		c.City, err = geo.CityForLatLng(c.LatitudeV, c.LongitudeV)
		if err != nil {
			return fail(fmt.Sprintf("Cannot find city for %v:%v - %s", c.Latitude, c.Longitude, err.Error()))
		}
		fallthrough

	case len(c.City) > 2:
		r := ServicesResp{}
		r.JID, r.Services, err = router.Services(c.City)
		if err != nil {
			return fail(fmt.Sprintf("Cannot find services for %v - %s", c.City, err.Error()))
		}
		return &r, nil
	}
	return nil, fmt.Errorf("Invalid location - lat: %v lng: %v  city: %v", c.Latitude, c.Longitude, c.City)
}
Exemple #2
0
func (c *SearchReq) run() (interface{}, error) {
	city, err := geo.CityForLatLng(c.LatitudeV, c.LongitudeV)
	if err != nil {
		return nil, fmt.Errorf("The lat/lng: %v:%v is not in a city", c.LatitudeV, c.LongitudeV)
	}
	fmt.Printf("[toCSSearchLL] city: %q\n", city)

	switch c.bkend {
	case "CitySourced":
		return c.processCS()
	}
	return nil, fmt.Errorf("Unsupported backend: %q", c.bkend)
}