From c1ca27a2b6bac52d6d84b39ad0fb741565946973 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Thu, 31 Mar 2016 16:08:08 +0200 Subject: [PATCH] Use a HTTP client with explicit timeout --- main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 6b478b7..a468587 100644 --- a/main.go +++ b/main.go @@ -35,9 +35,12 @@ func init() { } func main() { + timedClient := http.DefaultClient + timedClient.Timeout = 10 * time.Second + for { s := sealStatus{} - r, err := http.Get(config.VaultInstance + "/v1/sys/seal-status") + r, err := timedClient.Get(config.VaultInstance + "/v1/sys/seal-status") if err != nil { log.Printf("An error ocurred while reading seal-status: %s\n", err) os.Exit(1) @@ -57,7 +60,7 @@ func main() { "key": token, }) r, _ := http.NewRequest("PUT", config.VaultInstance+"/v1/sys/unseal", body) - resp, err := http.DefaultClient.Do(r) + resp, err := timedClient.Do(r) if err != nil { log.Printf("An error ocurred while doing unseal: %s\n", err) os.Exit(1)