@@ -10,16 +10,29 @@ import (
10
10
11
11
const _defaultLookupTimeout = 3 * time .Second
12
12
13
+ type lookupHostFn func (context.Context , string ) ([]string , error )
14
+
13
15
// DNSHostProviderOption is an option for the DNSHostProvider.
14
- type DNSHostProviderOption func (* DNSHostProvider )
16
+ type DNSHostProviderOption interface {
17
+ apply (* DNSHostProvider )
18
+ }
19
+
20
+ type lookupTimeoutOption struct {
21
+ timeout time.Duration
22
+ }
15
23
16
24
// WithLookupTimeout returns a DNSHostProviderOption that sets the lookup timeout.
17
25
func WithLookupTimeout (timeout time.Duration ) DNSHostProviderOption {
18
- return func ( provider * DNSHostProvider ) {
19
- provider . lookupTimeout = timeout
26
+ return lookupTimeoutOption {
27
+ timeout : timeout ,
20
28
}
21
29
}
22
30
31
+ func (o lookupTimeoutOption ) apply (provider * DNSHostProvider ) {
32
+ provider .lookupTimeout = o .timeout
33
+ }
34
+
35
+
23
36
// DNSHostProvider is the default HostProvider. It currently matches
24
37
// the Java StaticHostProvider, resolving hosts from DNS once during
25
38
// the call to Init. It could be easily extended to re-query DNS
@@ -30,7 +43,7 @@ type DNSHostProvider struct {
30
43
curr int
31
44
last int
32
45
lookupTimeout time.Duration
33
- lookupHost func (context. Context , string ) ([] string , error ) // Override of net.LookupHost, for testing.
46
+ lookupHost lookupHostFn // Override of net.LookupHost, for testing.
34
47
}
35
48
36
49
// NewDNSHostProvider creates a new DNSHostProvider with the given options.
0 commit comments