From 56ba1e640410fa8d4cd2edff23d172d5e3d2ca07 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Sat, 5 Dec 2020 20:55:33 -0800 Subject: [PATCH] If GET /index fails, try agin in 500ms --- files.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/files.go b/files.go index 504f0aa..69210a9 100644 --- a/files.go +++ b/files.go @@ -13,6 +13,7 @@ import ( "path/filepath" "strconv" "strings" + "time" ) // Save encrypted key to file @@ -117,9 +118,14 @@ func RecvFiles(senderAddr string) { log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr}).Hook(FatalHook{}) // Get server address by getting the IP without the port, prepending http:// and appending :9898 serverAddr := "http://" + strings.Split(senderAddr, ":")[0] + ":9898" + var response *http.Response // GET /index on sender's HTTP server response, err := http.Get(serverAddr + "/index") - if err != nil { log.Fatal().Err(err).Msg("Error getting 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") } + } // Close response body at the end of this function defer response.Body.Close() // Create index slice for storage of file index