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:
parent
e7204794e2
commit
5958c548fe
1 changed files with 27 additions and 0 deletions
27
http/get.go
Normal file
27
http/get.go
Normal 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue