mirror of
https://gitlab.com/pnx-tools/dns-updater.git
synced 2026-06-16 05:54:56 +02:00
32 lines
663 B
Go
32 lines
663 B
Go
package resolver
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"time"
|
|
|
|
"dnsupdater/ip"
|
|
)
|
|
|
|
// Interface that IP Lookup Services must implement.
|
|
type Service interface {
|
|
// Get the name of the serivce
|
|
Name() string
|
|
|
|
// Lookup the public ip.
|
|
Lookup(ctx context.Context) (net.IP, error)
|
|
}
|
|
|
|
// Constant name for the virtual WAN interface
|
|
const WAN_IFACE = "wan"
|
|
|
|
func LookupWrapper(service Service) ip.NetInterfaceIPResolver {
|
|
return func(iface_name string) (net.IP, error) {
|
|
if iface_name == WAN_IFACE {
|
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
|
|
defer cancel()
|
|
return service.Lookup(ctx)
|
|
}
|
|
return ip.GetInterfaceIP(iface_name)
|
|
}
|
|
}
|