Skip to content

Commit

Permalink
Basic Weather widget API key validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Cummer committed Jun 13, 2018
1 parent e1edb92 commit 6aec41d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions weather/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
12 changes: 12 additions & 0 deletions weather/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6aec41d

Please sign in to comment.