From d0ef8500358a744ce15d6b9fa476c05651c6f334 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 14 Nov 2021 16:37:43 +0100 Subject: [PATCH] Add and fix noctx linter --- .golangci.yaml | 1 - derp.go | 12 +++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 9139bba9..f74bc011 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -30,7 +30,6 @@ linters: - stylecheck - wrapcheck - paralleltest - - noctx - nlreturn - ifshort - gomnd diff --git a/derp.go b/derp.go index 422b1e62..fb06381b 100644 --- a/derp.go +++ b/derp.go @@ -1,6 +1,7 @@ package headscale import ( + "context" "encoding/json" "io" "io/ioutil" @@ -30,10 +31,19 @@ func loadDERPMapFromPath(path string) (*tailcfg.DERPMap, error) { } func loadDERPMapFromURL(addr url.URL) (*tailcfg.DERPMap, error) { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + + req, err := http.NewRequestWithContext(ctx, "GET", addr.String(), nil) + if err != nil { + return nil, err + } + client := http.Client{ Timeout: 10 * time.Second, } - resp, err := client.Get(addr.String()) + + resp, err := client.Do(req) if err != nil { return nil, err }