From 55f812d53c1afc57a69862e50c85a8fb4a95f0fc Mon Sep 17 00:00:00 2001 From: Sam Van der Borght Date: Wed, 21 Jun 2023 12:24:18 +0200 Subject: [PATCH] fix types --- model.go | 58 ++++++++++++++++++++++++++---------------------------- service.go | 15 +++++++------- 2 files changed, 35 insertions(+), 38 deletions(-) diff --git a/model.go b/model.go index a440e82..2f2a19c 100644 --- a/model.go +++ b/model.go @@ -17,36 +17,34 @@ type Tomorrow_Report struct { } type Tomorrow_Values struct { - CloudBase float64 `json:"cloudBase"` - CloudCeiling interface{} `json:"cloudCeiling"` - CloudCover int `json:"cloudCover"` - DewPoint float64 `json:"dewPoint"` - Evapotranspiration float64 `json:"evapotranspiration"` - FreezingRainIntensity int `json:"freezingRainIntensity"` - Humidity int `json:"humidity"` - IceAccumulation int `json:"iceAccumulation"` - IceAccumulationLwe int `json:"iceAccumulationLwe"` - PrecipitationProbability int `json:"precipitationProbability"` - PressureSurfaceLevel float64 `json:"pressureSurfaceLevel"` - RainAccumulation int `json:"rainAccumulation"` - RainAccumulationLwe int `json:"rainAccumulationLwe"` - RainIntensity int `json:"rainIntensity"` - SleetAccumulation int `json:"sleetAccumulation"` - SleetAccumulationLwe int `json:"sleetAccumulationLwe"` - SleetIntensity int `json:"sleetIntensity"` - SnowAccumulation int `json:"snowAccumulation"` - SnowAccumulationLwe int `json:"snowAccumulationLwe"` - SnowDepth int `json:"snowDepth"` - SnowIntensity int `json:"snowIntensity"` - Temperature float64 `json:"temperature"` - TemperatureApparent float64 `json:"temperatureApparent"` - UvHealthConcern int `json:"uvHealthConcern"` - UvIndex int `json:"uvIndex"` - Visibility int `json:"visibility"` - WeatherCode int `json:"weatherCode"` - WindDirection float64 `json:"windDirection"` - WindGust float64 `json:"windGust"` - WindSpeed float64 `json:"windSpeed"` + CloudBase float64 `json:"cloudBase"` + CloudCeiling float64 `json:"cloudCeiling"` + CloudCover float64 `json:"cloudCover"` + DewPoint float64 `json:"dewPoint"` + FreezingRainIntensity int `json:"freezingRainIntensity"` + Humidity float64 `json:"humidity"` + IceAccumulation int `json:"iceAccumulation"` + IceAccumulationLwe int `json:"iceAccumulationLwe"` + PrecipitationProbability int `json:"precipitationProbability"` + PressureSurfaceLevel float64 `json:"pressureSurfaceLevel"` + RainAccumulation int `json:"rainAccumulation"` + RainAccumulationLwe int `json:"rainAccumulationLwe"` + RainIntensity float64 `json:"rainIntensity"` + SleetAccumulation int `json:"sleetAccumulation"` + SleetAccumulationLwe int `json:"sleetAccumulationLwe"` + SleetIntensity int `json:"sleetIntensity"` + SnowAccumulation int `json:"snowAccumulation"` + SnowAccumulationLwe int `json:"snowAccumulationLwe"` + SnowIntensity int `json:"snowIntensity"` + Temperature float64 `json:"temperature"` + TemperatureApparent float64 `json:"temperatureApparent"` + UVHealthConcern int `json:"uvHealthConcern"` + UVIndex float64 `json:"uvIndex"` + Visibility int `json:"visibility"` + WeatherCode int `json:"weatherCode"` + WindDirection float64 `json:"windDirection"` + WindGust float64 `json:"windGust"` + WindSpeed float64 `json:"windSpeed"` } type DarkSky_Forecast struct { diff --git a/service.go b/service.go index d7ef1ad..bd51cec 100644 --- a/service.go +++ b/service.go @@ -6,7 +6,6 @@ import ( "github.com/rs/zerolog/log" "io/ioutil" "net/http" - "net/http/httputil" "net/url" "os" "strconv" @@ -89,9 +88,9 @@ func (s *Service) downloadReport(longitude, latitude float64) (*Tomorrow_Forecas if err != nil { return nil, err } - dump, _ := httputil.DumpResponse(resp, true) - log.Debug().Msg("api response received") - fmt.Printf("%s", dump) + //dump, _ := httputil.DumpResponse(resp, true) + //log.Debug().Msg("api response received") + //fmt.Printf("%s", dump) if resp.StatusCode != 200 { return nil, fmt.Errorf("invalid response with code %d, error: %s", resp.StatusCode, resp.Status) } @@ -145,17 +144,17 @@ func (s *Service) WriteXML(w http.ResponseWriter, result interface{}) { windBearing += 360 } xml += fmt.Sprintf("
%.0f
", windBearing) - xml += fmt.Sprintf("%5.1f", hourly.Values.RainIntensity) + xml += fmt.Sprintf("%0.1f", hourly.Values.RainIntensity) xml += fmt.Sprintf("%.0f", hourly.Values.PressureSurfaceLevel) xml += fmt.Sprintf("%.0f", hourly.Values.Humidity*100) xml += fmt.Sprintf("%.1f", hourly.Values.TemperatureApparent) - xml += fmt.Sprintf("%4.0f", hourly.Values.UvIndex*100) + xml += fmt.Sprintf("%4.0f", hourly.Values.UVIndex*100) xml += fmt.Sprintf("%d", s.fixIcon(hourly)) xml += fmt.Sprintf("%.1f", hourly.Values.WindGust*100/3600) xml += "0" xml += fmt.Sprintf("%.0f", hourly.Values.CloudCover*100) xml += "0" - xml += fmt.Sprintf("%.0f", hourly.Values.UvIndex) + xml += fmt.Sprintf("%.0f", hourly.Values.UVIndex) xml += "" } xml += "\n" @@ -168,5 +167,5 @@ func (s *Service) WriteXML(w http.ResponseWriter, result interface{}) { func (s *Service) fixIcon(report Tomorrow_Report) int { //return fixDarkSky2(report) - return fixTomorrow(report) + return getWeatherCondition(report.Values.WeatherCode) }