1
0
Fork 0

ip/resolver/basic_http/service.go: add support for a decoder function to be added to the service.

This commit is contained in:
Henrik Hautakoski 2023-12-25 21:29:56 +01:00
parent b2232a8fa7
commit 42d5d57314

View file

@ -11,10 +11,13 @@ import (
"dnsupdater/ip/internal" "dnsupdater/ip/internal"
) )
type Decoder func(io.Reader) ([]byte, error)
type Service struct { type Service struct {
ServiceName string ServiceName string
Url string Url string
Headers http.Header Headers http.Header
Decoder Decoder
} }
func (s Service) Name() string { func (s Service) Name() string {
@ -27,7 +30,11 @@ func (s Service) Lookup(ctx context.Context) (net.IP, error) {
return nil, err return nil, err
} }
body, err := io.ReadAll(resp.Body) if s.Decoder == nil {
s.Decoder = io.ReadAll
}
body, err := s.Decoder(resp.Body)
if err != nil { if err != nil {
return nil, err return nil, err
} }