Split out data fetching to function
parent
4e925bdb31
commit
87e6ba7adf
|
@ -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…
Reference in New Issue