// GetWeatherReport gets the weather report
GetWeatherReport gets the weather report
// GetWeatherReport gets the weather report
func (s OpenWeatherService) GetWeatherReport(ctx context.Context, lat, long string) (WeatherReport, error) {
	ctx, seg := xray.BeginSubsegment(ctx, "openweather-service")
	retval := WeatherReport{}
	apikey := os.Getenv("OPENWEATHER_API_KEY")
	if apikey == "" {
		seg.AddError(fmt.Errorf("{OPENWEATHER_API_KEY} key is blank but shouldn't be"))
		return retval, fmt.Errorf("{OPENWEATHER_API_KEY} key is blank but shouldn't be")
	}
	clientRequest, err := http.NewRequest("GET", "https://api.openweathermap.org/data/2.5/onecall", nil)
	if err != nil {
		seg.AddError(err)
		return retval, fmt.Errorf("problem creating request to openweather: %v", err)
	}
	q := clientRequest.URL.Query()
	q.Add("lat", lat)
	q.Add("lon", long)
	q.Add("units", "imperial")
	q.Add("appid", apikey)
	clientRequest.URL.RawQuery = q.Encode()
	clientRequest.Header.Set("Content-Type", "application/json; charset=UTF-8")
	client := &http.Client{}
	clientResponse, err := ctxhttp.Do(ctx, xray.Client(client), clientRequest)
	if err != nil {
		seg.AddError(err)
		return retval, fmt.Errorf("error when sending request to OpenWeather API server: %v", err)
	}
	defer clientResponse.Body.Close()
	owResponse := OpenWeatherResponse{}
	err = json.NewDecoder(clientResponse.Body).Decode(&owResponse)
	if err != nil {
		seg.AddError(err)
		return retval, fmt.Errorf("problem decoding the response from the OpenWeather API server: %v", err)
	}
	dailyPoints := []WeatherDataPoint{}
	for _, item := range owResponse.Daily {
		dailyPoint := WeatherDataPoint{
			ApparentTemperature: item.FeelsLike.Day,
			CloudCover:          float64(item.Clouds),
			Humidity:            float64(item.Humidity),
			Icon:                item.Weather[0].Icon,
			UVIndex:             item.Uvi,
			PrecipAccumulation:  item.Rain,
			PrecipProbability:   item.Pop,
			Pressure:            float64(item.Pressure),
			Summary:             item.Weather[0].Description,
			TemperatureMin:      item.Temp.Min,
			Temperature:         item.Temp.Day,
			TemperatureMax:      item.Temp.Max,
			Time:                int64(item.Dt),
			WindBearing:         float64(item.WindDeg),
			WindGust:            item.WindGust,
			WindSpeed:           item.WindSpeed,
		}
		dailyPoints = append(dailyPoints, dailyPoint)
	}
	hourlyPoints := []WeatherDataPoint{}
	for _, item := range owResponse.Hourly {
		hourlyPoint := WeatherDataPoint{
			ApparentTemperature: item.FeelsLike,
			CloudCover:          float64(item.Clouds),
			Humidity:            float64(item.Humidity),
			Icon:                item.Weather[0].Icon,
			UVIndex:             item.Uvi,
			PrecipAccumulation:  item.Rain.OneH,
			PrecipProbability:   item.Pop,
			Pressure:            float64(item.Pressure),
			Summary:             item.Weather[0].Description,
			Temperature:         item.Temp,
			TemperatureMax:      item.Temp,
			Time:                int64(item.Dt),
			WindBearing:         item.WindDeg,
			WindGust:            item.WindGust,
			WindSpeed:           item.WindSpeed,
		}
		hourlyPoints = append(hourlyPoints, hourlyPoint)
	}
	minutelyPoints := []MinuteDataPoint{}
	for _, item := range owResponse.Minutely {
		minutePoint := MinuteDataPoint{
			DateTime:      int64(item.Dt),
			Precipitation: item.Precipitation,
		}
		minutelyPoints = append(minutelyPoints, minutePoint)
	}
	retval = WeatherReport{
		Latitude:  owResponse.Lat,
		Longitude: owResponse.Lon,
		Currently: WeatherDataPoint{
			ApparentTemperature: owResponse.Current.FeelsLike,
			CloudCover:          float64(owResponse.Current.Clouds),
			Humidity:            float64(owResponse.Current.Humidity),
			Icon:                owResponse.Current.Weather[0].Icon,
			UVIndex:             owResponse.Current.Uvi,
			PrecipAccumulation:  owResponse.Current.Rain.LastHour,
			Pressure:            float64(owResponse.Current.Pressure),
			Summary:             owResponse.Current.Weather[0].Description,
			Temperature:         owResponse.Current.Temp,
			Time:                int64(owResponse.Current.Dt),
			WindBearing:         float64(owResponse.Current.WindDeg),
			WindSpeed:           owResponse.Current.WindSpeed,
		},
		Hourly:   hourlyPoints,
		Minutely: minutelyPoints,
		Daily: WeatherDataBlock{
			Data: dailyPoints,
		},
	}
	xray.AddMetadata(ctx, "OpenWeatherResult", retval)
	seg.Close(nil)
	return retval, nil
}
func ( s OpenWeatherService ) GetWeatherReport ( ctx context . Context , lat , long string ) ( WeatherReport , error ) { ctx , seg := xray . BeginSubsegment ( ctx , " " ) retval := WeatherReport { } apikey := os . Getenv ( " " ) if apikey == " " { seg . AddError ( fmt . Errorf ( " " ) ) return retval , fmt . Errorf ( " " ) } clientRequest , err := http . NewRequest ( " " , " " , nil ) if err != nil { seg . AddError ( err ) return retval , fmt . Errorf ( " " , err ) } q := clientRequest . URL . Query ( ) q . Add ( " " , lat ) q . Add ( " " , long ) q . Add ( " " , " " ) q . Add ( " " , apikey ) clientRequest . URL . RawQuery = q . Encode ( ) clientRequest . Header . Set ( " " , " " ) client := & http . Client { } clientResponse , err := ctxhttp . Do ( ctx , xray . Client ( client ) , clientRequest ) if err != nil { seg . AddError ( err ) return retval , fmt . Errorf ( " " , err ) } defer clientResponse . Body . Close ( ) owResponse := OpenWeatherResponse { } err = json . NewDecoder ( clientResponse . Body ) . Decode ( & owResponse ) if err != nil { seg . AddError ( err ) return retval , fmt . Errorf ( " " , err ) } dailyPoints := [ ] WeatherDataPoint { } for _ , item := range owResponse . Daily { dailyPoint := WeatherDataPoint { ApparentTemperature : item . FeelsLike . Day , CloudCover : float64 ( item . Clouds ) , Humidity : float64 ( item . Humidity ) , Icon : item . Weather [ 0 ] . Icon , UVIndex : item . Uvi , PrecipAccumulation : item . Rain , PrecipProbability : item . Pop , Pressure : float64 ( item . Pressure ) , Summary : item . Weather [ 0 ] . Description , TemperatureMin : item . Temp . Min , Temperature : item . Temp . Day , TemperatureMax : item . Temp . Max , Time : int64 ( item . Dt ) , WindBearing : float64 ( item . WindDeg ) , WindGust : item . WindGust , WindSpeed : item . WindSpeed , } dailyPoints = append ( dailyPoints , dailyPoint ) } hourlyPoints := [ ] WeatherDataPoint { } for _ , item := range owResponse . Hourly { hourlyPoint := WeatherDataPoint { ApparentTemperature : item . FeelsLike , CloudCover : float64 ( item . Clouds ) , Humidity : float64 ( item . Humidity ) , Icon : item . Weather [ 0 ] . Icon , UVIndex : item . Uvi , PrecipAccumulation : item . Rain . OneH , PrecipProbability : item . Pop , Pressure : float64 ( item . Pressure ) , Summary : item . Weather [ 0 ] . Description , Temperature : item . Temp , TemperatureMax : item . Temp , Time : int64 ( item . Dt ) , WindBearing : item . WindDeg , WindGust : item . WindGust , WindSpeed : item . WindSpeed , } hourlyPoints = append ( hourlyPoints , hourlyPoint ) } minutelyPoints := [ ] MinuteDataPoint { } for _ , item := range owResponse . Minutely { minutePoint := MinuteDataPoint { DateTime : int64 ( item . Dt ) , Precipitation : item . Precipitation , } minutelyPoints = append ( minutelyPoints , minutePoint ) } retval = WeatherReport { Latitude : owResponse . Lat , Longitude : owResponse . Lon , Currently : WeatherDataPoint { ApparentTemperature : owResponse . Current . FeelsLike , CloudCover : float64 ( owResponse . Current . Clouds ) , Humidity : float64 ( owResponse . Current . Humidity ) , Icon : owResponse . Current . Weather [ 0 ] . Icon , UVIndex : owResponse . Current . Uvi , PrecipAccumulation : owResponse . Current . Rain . LastHour , Pressure : float64 ( owResponse . Current . Pressure ) , Summary : owResponse . Current . Weather [ 0 ] . Description , Temperature : owResponse . Current . Temp , Time : int64 ( owResponse . Current . Dt ) , WindBearing : float64 ( owResponse . Current . WindDeg ) , WindSpeed : owResponse . Current . WindSpeed , } , Hourly : hourlyPoints , Minutely : minutelyPoints , Daily : WeatherDataBlock { Data : dailyPoints , } , } xray . AddMetadata ( ctx , " " , retval ) seg . Close ( nil ) return retval , nil }
GetWeatherReport gets the weather report
GetWeatherReport gets the weather report
//	Start the service segment //	The default return value //	Get the api key: //	Create our request: //	Set our headers //	Execute the request //	Decode the response: //	Get the daily points: //	Set the weather data points: //	Grab the current daily point //	Add our daily point: //	Get the hourly points: //	Set the weather data points: //	Grab the current hourly point //	Add our point: //	Get the minutely points: //	Set the weather data points: //	Grab the current hourly point //	Add our point: //	Format our weather report // Close the segment