@@ -206,7 +206,22 @@ func DialConfig(url string, config Config) (*Connection, error) {
206
206
}
207
207
208
208
if config .SASL == nil {
209
- config .SASL = []Authentication {uri .PlainAuth ()}
209
+ if uri .AuthMechanism != nil {
210
+ for _ , identifier := range uri .AuthMechanism {
211
+ switch strings .ToUpper (identifier ) {
212
+ case "PLAIN" :
213
+ config .SASL = append (config .SASL , uri .PlainAuth ())
214
+ case "AMQPLAIN" :
215
+ config .SASL = append (config .SASL , uri .AMQPlainAuth ())
216
+ case "EXTERNAL" :
217
+ config .SASL = append (config .SASL , & ExternalAuth {})
218
+ default :
219
+ return nil , fmt .Errorf ("unsupported auth_mechanism: %v" , identifier )
220
+ }
221
+ }
222
+ } else {
223
+ config .SASL = []Authentication {uri .PlainAuth ()}
224
+ }
210
225
}
211
226
212
227
if config .Vhost == "" {
@@ -226,21 +241,6 @@ func DialConfig(url string, config Config) (*Connection, error) {
226
241
connectionTimeout = time .Duration (uri .ConnectionTimeout ) * time .Millisecond
227
242
}
228
243
229
- if config .SASL == nil && uri .AuthMechanism != nil {
230
- for _ , identifier := range uri .AuthMechanism {
231
- switch strings .ToUpper (identifier ) {
232
- case "PLAIN" :
233
- config .SASL = append (config .SASL , uri .PlainAuth ())
234
- case "AMQPLAIN" :
235
- config .SASL = append (config .SASL , uri .AMQPlainAuth ())
236
- case "EXTERNAL" :
237
- config .SASL = append (config .SASL , & ExternalAuth {})
238
- default :
239
- return nil , fmt .Errorf ("unsupported auth_mechanism: %v" , identifier )
240
- }
241
- }
242
- }
243
-
244
244
addr := net .JoinHostPort (uri .Host , strconv .FormatInt (int64 (uri .Port ), 10 ))
245
245
246
246
dialer := config .Dial
0 commit comments