From 3d4d212e08b91c60cd8eb58bde1598b0ae9c1e93 Mon Sep 17 00:00:00 2001 From: Joakim Olsson Date: Mon, 11 Feb 2019 19:53:44 +0100 Subject: [PATCH] Only try to send a result back if at least one result came back --- main.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index a803c79..0841d3e 100644 --- a/main.go +++ b/main.go @@ -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) + } } } }