mirror of
https://gitlab.com/pnx-tools/dns-updater.git
synced 2026-06-16 05:54:56 +02:00
27 lines
516 B
Go
27 lines
516 B
Go
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
|
|
}
|