mirror of
https://gitlab.com/pnx-tools/dns-updater.git
synced 2026-06-16 05:54:56 +02:00
42 lines
633 B
Go
42 lines
633 B
Go
package basic_http
|
|
|
|
import (
|
|
"io"
|
|
"net"
|
|
"net/http"
|
|
"strings"
|
|
)
|
|
|
|
type Service struct {
|
|
ServiceName string
|
|
Url string
|
|
Headers http.Header
|
|
}
|
|
|
|
func (s Service) Name() string {
|
|
return s.ServiceName
|
|
}
|
|
|
|
func (s Service) Lookup() (net.IP, error) {
|
|
req, err := http.NewRequest("GET", s.Url, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
req.Header = s.Headers
|
|
|
|
resp, err := http.DefaultClient.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Trim spaces and stuff.
|
|
ip_str := strings.TrimSpace(string(body))
|
|
|
|
return net.ParseIP(ip_str), err
|
|
}
|