diff --git a/weather/display.go b/weather/display.go index 1b237789..9acd9e3d 100644 --- a/weather/display.go +++ b/weather/display.go @@ -11,6 +11,11 @@ import ( func (widget *Widget) display() { widget.View.Clear() + if widget.apiKeyValid() == false { + fmt.Fprintf(widget.View, "%s", " Environment variable WTF_OWM_API_KEY is not set") + return + } + cityData := widget.currentData() if cityData == nil { fmt.Fprintf(widget.View, "%s", " Weather data is unavailable (1)") diff --git a/weather/widget.go b/weather/widget.go index 992c7207..fa92b60d 100644 --- a/weather/widget.go +++ b/weather/widget.go @@ -104,6 +104,18 @@ func (widget *Widget) Prev() { /* -------------------- Unexported Functions -------------------- */ +func (widget *Widget) apiKeyValid() bool { + if widget.APIKey == "" { + return false + } + + if len(widget.APIKey) != 32 { + return false + } + + return true +} + func (widget *Widget) currentData() *owm.CurrentWeatherData { if len(widget.Data) == 0 { return nil