diff options
| author | Mel <mel@rnrd.eu> | 2026-08-20 22:05:41 +0200 |
|---|---|---|
| committer | Mel <mel@rnrd.eu> | 2026-08-20 22:05:41 +0200 |
| commit | f896a9775c34c0e095273c193806ca245dfae940 (patch) | |
| tree | c07736e8243d22891f9a549d0b712a7d0b074482 /source/icanhazip.go | |
| parent | a81cf3b385e45587a6be51f7958f9042975fc0c6 (diff) | |
| download | ddnnss-f896a9775c34c0e095273c193806ca245dfae940.tar.zst ddnnss-f896a9775c34c0e095273c193806ca245dfae940.zip | |
Add IPv4/IPv6 source from 'icanhazip.com'
Signed-off-by: Mel <mel@rnrd.eu>
Diffstat (limited to 'source/icanhazip.go')
| -rw-r--r-- | source/icanhazip.go | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/source/icanhazip.go b/source/icanhazip.go new file mode 100644 index 0000000..62f2d9f --- /dev/null +++ b/source/icanhazip.go @@ -0,0 +1,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) +} |
