From 04f2a8404a49b1d55e2e94718657280879cf04a9 Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 21 Mar 2018 18:59:41 +0000 Subject: Add structs for expected json to unmarshall into. Still need to switch to actually using them --- weather.go | 58 +++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 47 insertions(+), 11 deletions(-) diff --git a/weather.go b/weather.go index 7ca592e..b81cc9f 100644 --- a/weather.go +++ b/weather.go @@ -2,6 +2,8 @@ package main // TODO: allow free-text lookups of place names, rather than ids // TODO: decode weather type number +// TODO: split out met office specific stuff to separate module +// TODO: add other weather providers import ( "encoding/json" @@ -16,20 +18,54 @@ import ( const defid = "310118" var wkey = map[string]string{ - "f": "Feels Like Temperature", - "h": "Humidity", - "p": "Pressure", - "t": "Temperature", - "v": "Visibility", - "wg": "Wind Gust", - "ws": "Wind Speed", - "pp": "Precipitaton Probability", - "uv": "Max UV Index", - "wd": "Wind Direction", - "wt": "Weather Type", + "f": "Feels Like Temperature", + "h": "Humidity", + "p": "Pressure", + "t": "Temperature", + "v": "Visibility", + "wg": "Wind Gust", + "ws": "Wind Speed", + "pp": "Precipitaton Probability", + "uv": "Max UV Index", + "wd": "Wind Direction", + "wt": "Weather Type", "AQIndex": "Air Quality", } +type Response struct { + BestFcst struct { + Location struct { + Days []Day `json:"Day"` + } + } +} + +type Day struct { + DayValues WeatherParam + NightValues WeatherParam + TimeSteps struct { + TimeStep struct { + Time string `json:"@time"` + WeatherParams []WeatherParam + } + } +} + +type WeatherParam struct { + AQIndex float64 + F float64 + H float64 + P float64 + PP float64 + UV float64 + T float64 + V float64 + WD string + WG float64 + WS float64 + WT float64 +} + func main() { var j map[string]interface{} var id string -- cgit v1.2.3