1
0
Fork 0

rename ip/resolver/basic_http to ip/resolver/http

This commit is contained in:
Henrik Hautakoski 2023-12-25 21:41:42 +01:00
parent 0ad92e8e4a
commit ae60d3bf35
3 changed files with 8 additions and 8 deletions

View file

@ -1,46 +0,0 @@
package basic_http
import (
"context"
"io"
"net"
"net/http"
"strings"
httputils "dnsupdater/http"
"dnsupdater/ip/internal"
)
type Decoder func(io.Reader) ([]byte, error)
type Service struct {
ServiceName string
Url string
Headers http.Header
Decoder Decoder
}
func (s Service) Name() string {
return s.ServiceName
}
func (s Service) Lookup(ctx context.Context) (net.IP, error) {
resp, err := httputils.Get(ctx, s.Url, s.Headers)
if err != nil {
return nil, err
}
if s.Decoder == nil {
s.Decoder = io.ReadAll
}
body, err := s.Decoder(resp.Body)
if err != nil {
return nil, err
}
// Trim spaces and stuff.
ip_str := strings.TrimSpace(string(body))
return internal.ParseIP(ip_str)
}