Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom LookupIPAddr function #699

Merged
merged 4 commits into from
Nov 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions tcpdialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ var (
defaultDialer = &TCPDialer{Concurrency: 1000}
)

type Resolver interface {
LookupIPAddr(context.Context, string) (names []net.IPAddr, err error)
}

// TCPDialer contains options to control a group of Dial calls.
type TCPDialer struct {
// Concurrency controls the maximum number of concurrent Dails
Expand All @@ -141,7 +145,7 @@ type TCPDialer struct {
// },
// },
// }
Resolver *net.Resolver
Resolver Resolver

tcpAddrsLock sync.Mutex
tcpAddrsMap map[string]*tcpAddrEntry
Expand Down Expand Up @@ -426,7 +430,7 @@ func (d *TCPDialer) getTCPAddrs(addr string, dualStack bool) ([]net.TCPAddr, uin
return e.addrs, idx, nil
}

func resolveTCPAddrs(addr string, dualStack bool, resolver *net.Resolver) ([]net.TCPAddr, error) {
func resolveTCPAddrs(addr string, dualStack bool, resolver Resolver) ([]net.TCPAddr, error) {
host, portS, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
Expand All @@ -439,7 +443,7 @@ func resolveTCPAddrs(addr string, dualStack bool, resolver *net.Resolver) ([]net
if resolver == nil {
resolver = net.DefaultResolver
}

ctx := context.Background()
ipaddrs, err := resolver.LookupIPAddr(ctx, host)
if err != nil {
Expand Down