1
0
Fork 0

Adding ip/resolver/basic_http

This commit is contained in:
Henrik Hautakoski 2023-08-15 09:37:08 +02:00
parent 9f344a2ae9
commit 2ddf2dadd7
2 changed files with 95 additions and 0 deletions

View file

@ -0,0 +1,42 @@
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
}