ip/resolver/basic_http/service.go: use http get helper
This commit is contained in:
parent
5958c548fe
commit
89aee8e388
1 changed files with 2 additions and 13 deletions
|
|
@ -2,12 +2,12 @@ package basic_http
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
httputils "dnsupdater/http"
|
||||
"dnsupdater/ip"
|
||||
)
|
||||
|
||||
|
|
@ -22,22 +22,11 @@ func (s Service) Name() string {
|
|||
}
|
||||
|
||||
func (s Service) Lookup(ctx context.Context) (net.IP, error) {
|
||||
req, err := http.NewRequestWithContext(ctx, "GET", s.Url, nil)
|
||||
resp, err := httputils.Get(ctx, s.Url, s.Headers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header = s.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)
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue