1
0
Fork 0

ip/resolver/http/service.go: refactor default decoder function into its own module

This commit is contained in:
Henrik Hautakoski 2026-02-19 10:24:15 +01:00
parent c36a83c9b8
commit 1dedbbe2dd
3 changed files with 67 additions and 10 deletions

View file

@ -1,15 +1,14 @@
package http
import (
"bufio"
"context"
"io"
"net"
"net/http"
"strings"
httputils "dnsupdater/http"
"dnsupdater/ip/internal"
"dnsupdater/ip/resolver/decoder"
)
type Decoder func(io.Reader) (string, error)
@ -32,14 +31,7 @@ func (s Service) Lookup(ctx context.Context) (net.IP, error) {
}
if s.Decoder == nil {
s.Decoder = func(r io.Reader) (string, error) {
line, err := bufio.NewReader(r).ReadString('\n')
if err == nil || err == io.EOF {
line = strings.TrimRight(line, "\r\n")
line = strings.TrimSpace(line)
}
return line, err
}
s.Decoder = decoder.Text
}
body, err := s.Decoder(resp.Body)