diff --git a/dns_monitor.go b/dns_monitor.go index 59f7f2e..072e01c 100644 --- a/dns_monitor.go +++ b/dns_monitor.go @@ -197,11 +197,11 @@ func (m *DnsMonitor) Add(target string, callback DnsMonitorCallback) (*DnsMonito } hostname = parsed.Host } else { - // Hostname with optional port passed. + // Hostname only passed. hostname = target - if h, _, err := net.SplitHostPort(target); err == nil { - hostname = h - } + } + if h, _, err := net.SplitHostPort(hostname); err == nil { + hostname = h } m.mu.Lock() diff --git a/dns_monitor_test.go b/dns_monitor_test.go index eedae1c..5844501 100644 --- a/dns_monitor_test.go +++ b/dns_monitor_test.go @@ -240,7 +240,7 @@ func TestDnsMonitor(t *testing.T) { rec1 := newDnsMonitorReceiverForTest(t) rec1.Expect(ips1, ips1, nil, nil) - entry1, err := monitor.Add("https://foo", rec1.OnLookup) + entry1, err := monitor.Add("https://foo:12345", rec1.OnLookup) if err != nil { t.Fatal(err) }