Refactor
This commit is contained in:
parent
bd3aa5e948
commit
0f21902ffd
11 changed files with 96 additions and 80 deletions
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
|
||||
httputils "dnsupdater/http"
|
||||
"dnsupdater/ip"
|
||||
"dnsupdater/ip/internal"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
|
|
@ -35,5 +35,5 @@ func (s Service) Lookup(ctx context.Context) (net.IP, error) {
|
|||
// Trim spaces and stuff.
|
||||
ip_str := strings.TrimSpace(string(body))
|
||||
|
||||
return ip.ParseIP(ip_str)
|
||||
return internal.ParseIP(ip_str)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"net"
|
||||
|
||||
"dnsupdater/http"
|
||||
"dnsupdater/ip"
|
||||
"dnsupdater/ip/internal"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
|
|
@ -38,5 +38,5 @@ func (s Service) Lookup(ctx context.Context) (net.IP, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
return ip.ParseIP(v.Ip)
|
||||
return internal.ParseIP(v.Ip)
|
||||
}
|
||||
|
|
|
|||
18
ip/resolver/resolver.go
Normal file
18
ip/resolver/resolver.go
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
package resolver
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
)
|
||||
|
||||
// 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"
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue