blob: 62f2d9f8b4d0dc61aff66b11e00f9c62fc4c3fc4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package source
import (
"log/slog"
"net/netip"
)
type icanhazip struct {
log *slog.Logger
}
var _ Source = (*icanhazip)(nil)
func newICanHazIp(log *slog.Logger) (*icanhazip, error) {
return &icanhazip{log: log}, nil
}
func (icanhazip) Supports(Family) bool { return true }
func (s icanhazip) Lookup(family Family) (netip.Addr, error) {
s.log.Info("will look up address from the icanhazip.com service",
slog.String("family", string(family)),
)
if family == IPv6 {
return fetch("https://ipv6.icanhazip.com", IPv6)
}
return fetch("https://ipv4.icanhazip.com", IPv4)
}
|