make safer

This commit is contained in:
stryan 2021-10-20 19:59:12 -04:00
parent ac1db5cf75
commit 8f38a1e601

13
main.go
View File

@ -27,9 +27,14 @@ func LoadPatches(pl *PatchList, url string) {
res, err := http.Get(url)
defer res.Body.Close()
if err != nil {
log.Println(err)
log.Printf("Got %v, retrying in 5s", err)
time.Sleep(5 * time.Second)
res, err = http.Get(url)
if err != nil {
log.Printf("Got %v, not trying again", err)
return
}
}
body, readErr := ioutil.ReadAll(res.Body)
if readErr != nil {
log.Fatal(readErr)
@ -101,6 +106,10 @@ func main() {
flag.Parse()
LoadPatches(&patch_list, *sourcePtr)
if len(patch_list.Patches) <= 0 {
log.Fatal("error getting initial patch list")
}
current_patch = patch_list.Patches[len(patch_list.Patches)-1]
log.Println("Started bot, loaded patch list")
log.Printf("Starting on patch %v", current_patch.PatchNumber)
@ -114,6 +123,7 @@ func main() {
for {
time.Sleep(30 * time.Second)
LoadPatches(&patch_list, *sourcePtr)
if len(patch_list.Patches) > 0 {
newest_patch := patch_list.Patches[len(patch_list.Patches)-1]
if newest_patch.PatchNumber != current_patch.PatchNumber {
current_patch = newest_patch
@ -124,5 +134,6 @@ func main() {
}
}
}
}
}