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:
parent
d2dfcd8978
commit
b593f3517a
@ -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)")
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user