1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00

Handle cases in which there is no weather data

This commit is contained in:
Chris Cummer 2018-04-18 10:34:59 -07:00
parent 6bf98c6a03
commit f1a2f65bf1
2 changed files with 13 additions and 1 deletions

View File

@ -12,9 +12,13 @@ func (widget *Widget) display() {
widget.View.Clear() widget.View.Clear()
cityData := widget.currentData() cityData := widget.currentData()
if cityData == nil {
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (1)")
return
}
if len(cityData.Weather) == 0 { if len(cityData.Weather) == 0 {
fmt.Fprintf(widget.View, "%s", " Weather data is unavailable.") fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (2)")
return return
} }

View File

@ -91,6 +91,14 @@ func (widget *Widget) Prev() {
/* -------------------- Unexported Functions -------------------- */ /* -------------------- Unexported Functions -------------------- */
func (widget *Widget) currentData() *owm.CurrentWeatherData { func (widget *Widget) currentData() *owm.CurrentWeatherData {
if len(widget.Data) == 0 {
return nil
}
if widget.Idx < 0 || widget.Idx >= len(widget.Data) {
return nil
}
return widget.Data[widget.Idx] return widget.Data[widget.Idx]
} }