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:
parent
b2232a8fa7
commit
42d5d57314
1 changed files with 8 additions and 1 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue