From f84fbd542bf09a7e422e499ecf17278080a5cd89 Mon Sep 17 00:00:00 2001 From: Dominic Wong Date: Wed, 18 Aug 2021 17:39:00 +0100 Subject: [PATCH] Fix panic in weather forecast (#189) --- weather/handler/weather.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/weather/handler/weather.go b/weather/handler/weather.go index 2255dec..6cca421 100644 --- a/weather/handler/weather.go +++ b/weather/handler/weather.go @@ -92,8 +92,14 @@ func (w *Weather) Forecast(ctx context.Context, req *pb.ForecastRequest, rsp *pb if v := day["daily_will_it_rain"].(float64); v == 1.0 { willrain = true } - if v, _ := strconv.Atoi(day["daily_chance_of_rain"].(string)); v > 0 { - chancerain = int32(v) + + // is this a string or a float64? Try both + if dcr, ok := day["daily_chance_of_rain"].(string); ok { + if v, _ := strconv.Atoi(dcr); v > 0 { + chancerain = int32(v) + } + } else if dcr, ok := day["daily_chance_of_rain"].(float64); ok { + chancerain = int32(dcr) } // set the daily forecast