ConvertWeather converts domain.Weather to v1.resp
(w domain.Weather)
| 6 | |
| 7 | // ConvertWeather converts domain.Weather to v1.resp |
| 8 | func ConvertWeather(w domain.Weather) resp { |
| 9 | r := resp{} |
| 10 | |
| 11 | // Current condition |
| 12 | if len(w.CurrentCondition) > 0 { |
| 13 | cc := w.CurrentCondition[0] |
| 14 | r.Data.Cur = []cond{convertCondFromCurrent(cc)} |
| 15 | } |
| 16 | |
| 17 | // Request |
| 18 | if len(w.Request) > 0 { |
| 19 | r.Data.Req = []loc{ |
| 20 | { |
| 21 | Query: w.Request[0].Query, |
| 22 | Type: w.Request[0].Type, |
| 23 | }, |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | // Weather days |
| 28 | for _, wd := range w.Weather { |
| 29 | day := weather{ |
| 30 | Date: wd.Date, |
| 31 | MaxtempC: parseInt(wd.MaxTempC), |
| 32 | MintempC: parseInt(wd.MinTempC), |
| 33 | } |
| 34 | |
| 35 | // Astronomy |
| 36 | if len(wd.Astronomy) > 0 { |
| 37 | a := wd.Astronomy[0] |
| 38 | day.Astronomy = []astro{ |
| 39 | { |
| 40 | Moonrise: a.Moonrise, |
| 41 | Moonset: a.Moonset, |
| 42 | Sunrise: a.Sunrise, |
| 43 | Sunset: a.Sunset, |
| 44 | }, |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | // Hourly |
| 49 | for _, h := range wd.Hourly { |
| 50 | day.Hourly = append(day.Hourly, convertCondFromHourly(h)) |
| 51 | } |
| 52 | |
| 53 | r.Data.Weather = append(r.Data.Weather, day) |
| 54 | } |
| 55 | |
| 56 | return r |
| 57 | } |
| 58 | |
| 59 | // getTranslatedDesc returns the best available translation (lang_xx first, then English) |
| 60 | func getTranslatedDesc(weatherDesc, langXX []domain.ValueItem, fallback string) string { |
no test coverage detected