1
0
Fork 0
mirror of https://gitlab.com/pnx-tools/dns-updater.git synced 2026-06-16 05:54:56 +02:00

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"
)
type Decoder func(io.Reader) ([]byte, error)
type Service struct {
ServiceName string
Url string
Headers http.Header
Decoder Decoder
}
func (s Service) Name() string {
@ -27,7 +30,11 @@ func (s Service) Lookup(ctx context.Context) (net.IP, error) {
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 {
return nil, err
}