Split out data fetching to function

master
Elis Hirwing 5 years ago
parent 4e925bdb31
commit 87e6ba7adf
Signed by: etu
GPG Key ID: D57EFA625C9A925F
  1. 24
      src/statusscreen/SL.go

@ -58,16 +58,7 @@ func (sl *SL) GetOutput() []string {
// Check if it's time to refresh yet
if sl.nextRefresh <= time.Now().Unix() {
// If it is, refresh the data
sldata, err := sl.getTimeTable()
// If no error occured, save the latest data to the struct
if err == nil {
sl.lastResponse = sldata
sl.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
} else {
// log.Fatal(err)
}
sl.getData()
}
for _, v := range sl.lastResponse.ResponseData.Metros {
@ -89,6 +80,19 @@ func (sl *SL) GetOutput() []string {
return strings.Split(b.String(), "\n")
}
func (sl *SL) getData() {
// If it is, refresh the data
sldata, err := sl.getTimeTable()
// If no error occured, save the latest data to the struct
if err == nil {
sl.lastResponse = sldata
sl.nextRefresh = time.Now().Unix() + sl.Config.SL.RefreshDelay
} else {
// log.Fatal(err)
}
}
func (sl *SL) getTimeTable() (SLResponse, error) {
parsedResponse := SLResponse{}

Loading…
Cancel
Save