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

Basic Weather widget API key validation

This commit is contained in:
Chris Cummer 2018-06-09 04:07:01 -07:00
parent d2dfcd8978
commit b593f3517a
2 changed files with 17 additions and 0 deletions

View File

@ -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)")

View File

@ -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