Skip to content

Commit 360012b

Browse files
authored
chore: deprecate unnecessary wrapper for DialWithDialer and DialWithTLSConfig (#399)
1 parent bfb0013 commit 360012b

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

conn.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,39 @@ type DialOpt func(*DialContext)
119119
// DialWithDialer updates net.Dialer in DialContext.
120120
func DialWithDialer(d *net.Dialer) DialOpt {
121121
return func(dc *DialContext) {
122-
dc.d = d
122+
dc.dialer = d
123123
}
124124
}
125125

126126
// DialWithTLSConfig updates tls.Config in DialContext.
127127
func DialWithTLSConfig(tc *tls.Config) DialOpt {
128128
return func(dc *DialContext) {
129-
dc.tc = tc
129+
dc.tlsConfig = tc
130130
}
131131
}
132132

133133
// DialWithTLSDialer is a wrapper for DialWithTLSConfig with the option to
134134
// specify a net.Dialer to for example define a timeout or a custom resolver.
135+
// @deprecated Use DialWithDialer and DialWithTLSConfig instead
135136
func DialWithTLSDialer(tlsConfig *tls.Config, dialer *net.Dialer) DialOpt {
136137
return func(dc *DialContext) {
137-
dc.tc = tlsConfig
138-
dc.d = dialer
138+
dc.tlsConfig = tlsConfig
139+
dc.dialer = dialer
139140
}
140141
}
141142

142143
// DialContext contains necessary parameters to dial the given ldap URL.
143144
type DialContext struct {
144-
d *net.Dialer
145-
tc *tls.Config
145+
dialer *net.Dialer
146+
tlsConfig *tls.Config
146147
}
147148

148149
func (dc *DialContext) dial(u *url.URL) (net.Conn, error) {
149150
if u.Scheme == "ldapi" {
150151
if u.Path == "" || u.Path == "/" {
151152
u.Path = "/var/run/slapd/ldapi"
152153
}
153-
return dc.d.Dial("unix", u.Path)
154+
return dc.dialer.Dial("unix", u.Path)
154155
}
155156

156157
host, port, err := net.SplitHostPort(u.Host)
@@ -165,17 +166,17 @@ func (dc *DialContext) dial(u *url.URL) (net.Conn, error) {
165166
if port == "" {
166167
port = DefaultLdapPort
167168
}
168-
return dc.d.Dial("udp", net.JoinHostPort(host, port))
169+
return dc.dialer.Dial("udp", net.JoinHostPort(host, port))
169170
case "ldap":
170171
if port == "" {
171172
port = DefaultLdapPort
172173
}
173-
return dc.d.Dial("tcp", net.JoinHostPort(host, port))
174+
return dc.dialer.Dial("tcp", net.JoinHostPort(host, port))
174175
case "ldaps":
175176
if port == "" {
176177
port = DefaultLdapsPort
177178
}
178-
return tls.DialWithDialer(dc.d, "tcp", net.JoinHostPort(host, port), dc.tc)
179+
return tls.DialWithDialer(dc.dialer, "tcp", net.JoinHostPort(host, port), dc.tlsConfig)
179180
}
180181

181182
return nil, fmt.Errorf("Unknown scheme '%s'", u.Scheme)
@@ -221,8 +222,8 @@ func DialURL(addr string, opts ...DialOpt) (*Conn, error) {
221222
for _, opt := range opts {
222223
opt(&dc)
223224
}
224-
if dc.d == nil {
225-
dc.d = &net.Dialer{Timeout: DefaultTimeout}
225+
if dc.dialer == nil {
226+
dc.dialer = &net.Dialer{Timeout: DefaultTimeout}
226227
}
227228

228229
c, err := dc.dial(u)

v3/conn.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,39 @@ type DialOpt func(*DialContext)
119119
// DialWithDialer updates net.Dialer in DialContext.
120120
func DialWithDialer(d *net.Dialer) DialOpt {
121121
return func(dc *DialContext) {
122-
dc.d = d
122+
dc.dialer = d
123123
}
124124
}
125125

126126
// DialWithTLSConfig updates tls.Config in DialContext.
127127
func DialWithTLSConfig(tc *tls.Config) DialOpt {
128128
return func(dc *DialContext) {
129-
dc.tc = tc
129+
dc.tlsConfig = tc
130130
}
131131
}
132132

133133
// DialWithTLSDialer is a wrapper for DialWithTLSConfig with the option to
134134
// specify a net.Dialer to for example define a timeout or a custom resolver.
135+
// @deprecated Use DialWithDialer and DialWithTLSConfig instead
135136
func DialWithTLSDialer(tlsConfig *tls.Config, dialer *net.Dialer) DialOpt {
136137
return func(dc *DialContext) {
137-
dc.tc = tlsConfig
138-
dc.d = dialer
138+
dc.tlsConfig = tlsConfig
139+
dc.dialer = dialer
139140
}
140141
}
141142

142143
// DialContext contains necessary parameters to dial the given ldap URL.
143144
type DialContext struct {
144-
d *net.Dialer
145-
tc *tls.Config
145+
dialer *net.Dialer
146+
tlsConfig *tls.Config
146147
}
147148

148149
func (dc *DialContext) dial(u *url.URL) (net.Conn, error) {
149150
if u.Scheme == "ldapi" {
150151
if u.Path == "" || u.Path == "/" {
151152
u.Path = "/var/run/slapd/ldapi"
152153
}
153-
return dc.d.Dial("unix", u.Path)
154+
return dc.dialer.Dial("unix", u.Path)
154155
}
155156

156157
host, port, err := net.SplitHostPort(u.Host)
@@ -165,17 +166,17 @@ func (dc *DialContext) dial(u *url.URL) (net.Conn, error) {
165166
if port == "" {
166167
port = DefaultLdapPort
167168
}
168-
return dc.d.Dial("udp", net.JoinHostPort(host, port))
169+
return dc.dialer.Dial("udp", net.JoinHostPort(host, port))
169170
case "ldap":
170171
if port == "" {
171172
port = DefaultLdapPort
172173
}
173-
return dc.d.Dial("tcp", net.JoinHostPort(host, port))
174+
return dc.dialer.Dial("tcp", net.JoinHostPort(host, port))
174175
case "ldaps":
175176
if port == "" {
176177
port = DefaultLdapsPort
177178
}
178-
return tls.DialWithDialer(dc.d, "tcp", net.JoinHostPort(host, port), dc.tc)
179+
return tls.DialWithDialer(dc.dialer, "tcp", net.JoinHostPort(host, port), dc.tlsConfig)
179180
}
180181

181182
return nil, fmt.Errorf("Unknown scheme '%s'", u.Scheme)
@@ -221,8 +222,8 @@ func DialURL(addr string, opts ...DialOpt) (*Conn, error) {
221222
for _, opt := range opts {
222223
opt(&dc)
223224
}
224-
if dc.d == nil {
225-
dc.d = &net.Dialer{Timeout: DefaultTimeout}
225+
if dc.dialer == nil {
226+
dc.dialer = &net.Dialer{Timeout: DefaultTimeout}
226227
}
227228

228229
c, err := dc.dial(u)

0 commit comments

Comments
 (0)