1
0
Fork 0
mirror of https://gitlab.com/pnx-tools/dns-updater.git synced 2026-06-16 05:54:56 +02:00

Adding http/get.go

This commit is contained in:
Henrik Hautakoski 2023-12-02 14:35:21 +01:00
parent e7204794e2
commit 5958c548fe

27
http/get.go Normal file
View file

@ -0,0 +1,27 @@
package http
import (
"context"
"fmt"
"net/http"
)
// Perform a HTTP Get request.
func Get(ctx context.Context, url string, headers http.Header) (*http.Response, error) {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
return nil, err
}
req.Header = headers
resp, err := http.DefaultClient.Do(req)
if err != nil {
return nil, err
}
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
return nil, fmt.Errorf("HTTP Response: %s", resp.Status)
}
return resp, nil
}