Get weather in a goroutine as well

master
Elis Hirwing 5 years ago
parent 1e50b13b76
commit 23d000aac0
Signed by: etu
GPG Key ID: D57EFA625C9A925F
  1. 21
      src/statusscreen/Weather.go

@ -17,14 +17,8 @@ type Weather struct {
// GetOutput returns a rendered result of this module
func (weather *Weather) GetOutput() []string {
if weather.nextRefresh <= time.Now().Unix() {
myWeather, err := weather.getWeather()
if err == nil {
weather.lastResponse = myWeather
weather.nextRefresh = time.Now().Unix() + weather.Config.Weather.RefreshDelay
} else {
// log.Fatal(err)
}
weather.nextRefresh += 10
go weather.getData()
}
parts := strings.Split(weather.lastResponse, "\n")
@ -36,6 +30,17 @@ func (weather *Weather) GetOutput() []string {
return []string{}
}
func (weather *Weather) getData() {
myWeather, err := weather.getWeather()
if err == nil {
weather.lastResponse = myWeather
weather.nextRefresh = time.Now().Unix() + weather.Config.Weather.RefreshDelay
} else {
// log.Fatal(err)
}
}
func (weather *Weather) getWeather() (string, error) {
// Set up http client to fetch weather
client := &http.Client{

Loading…
Cancel
Save