ip/resolver/basic_http/service.go: add support for a decoder function to be added to the service.
This commit is contained in:
parent
b2232a8fa7
commit
42d5d57314
1 changed files with 8 additions and 1 deletions
|
|
@ -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
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue