From 1f60dd56dec51fa67300d06ea7d8277566362e3e Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 5 Dec 2020 20:59:38 -0800 Subject: [PATCH] If GET /index fails, retry in 500ms --- files.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/files.go b/files.go index 69210a9..ba74a7e 100644 --- a/files.go +++ b/files.go @@ -122,9 +122,12 @@ func RecvFiles(senderAddr string) { // GET /index on sender's HTTP server response, err := http.Get(serverAddr + "/index") if err != nil { - time.Sleep(500*time.Millisecond) - response, err = http.Get(serverAddr + "/index") - if err != nil { log.Fatal().Err(err).Msg("Error getting index") } + indexGetFailed := true + for indexGetFailed { + response, err = http.Get(serverAddr + "/index") + if err != nil { log.Fatal().Err(err).Msg("Error getting index") } else {indexGetFailed = false} + time.Sleep(500*time.Millisecond) + } } // Close response body at the end of this function defer response.Body.Close()