Only try to send a result back if at least one result came back

This commit is contained in:
2019-02-11 19:53:44 +01:00
parent 3a7f85ead7
commit 3d4d212e08
+14 -12
View File
@@ -71,19 +71,21 @@ func main() {
if result, err := c.Geocode(context.Background(), r); err != nil {
log.Fatalf("fatal error: %s", err)
} else {
l := location{
Name: e.Name,
City: e.City,
Municipality: e.Municipality,
State: e.State,
Lat: result[0].Geometry.Location.Lat,
Long: result[0].Geometry.Location.Lng,
}
if response, err := json.Marshal(l); err != nil {
log.Fatalf("fatal error: %s", err)
} else {
if err := sc.Publish("DanceHall.Location", response); err != nil {
if len(result) > 0 {
l := location{
Name: e.Name,
City: e.City,
Municipality: e.Municipality,
State: e.State,
Lat: result[0].Geometry.Location.Lat,
Long: result[0].Geometry.Location.Lng,
}
if response, err := json.Marshal(l); err != nil {
log.Fatalf("fatal error: %s", err)
} else {
if err := sc.Publish("DanceHall.Location", response); err != nil {
log.Fatalf("fatal error: %s", err)
}
}
}
}