@@ -152,11 +152,11 @@ func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err er
152
152
ctx := octx
153
153
fallbackConfigs , err = expandWithIPs (ctx , config .LookupFunc , fallbackConfigs )
154
154
if err != nil {
155
- return nil , & connectError { config : config , msg : "hostname resolving error" , err : err }
155
+ return nil , & ConnectError { Config : config , msg : "hostname resolving error" , err : err }
156
156
}
157
157
158
158
if len (fallbackConfigs ) == 0 {
159
- return nil , & connectError { config : config , msg : "hostname resolving error" , err : errors .New ("ip addr wasn't found" )}
159
+ return nil , & ConnectError { Config : config , msg : "hostname resolving error" , err : errors .New ("ip addr wasn't found" )}
160
160
}
161
161
162
162
foundBestServer := false
@@ -178,7 +178,7 @@ func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err er
178
178
foundBestServer = true
179
179
break
180
180
} else if pgerr , ok := err .(* PgError ); ok {
181
- err = & connectError { config : config , msg : "server error" , err : pgerr }
181
+ err = & ConnectError { Config : config , msg : "server error" , err : pgerr }
182
182
const ERRCODE_INVALID_PASSWORD = "28P01" // wrong password
183
183
const ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION = "28000" // wrong password or bad pg_hba.conf settings
184
184
const ERRCODE_INVALID_CATALOG_NAME = "3D000" // db does not exist
@@ -189,7 +189,7 @@ func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err er
189
189
pgerr .Code == ERRCODE_INSUFFICIENT_PRIVILEGE {
190
190
break
191
191
}
192
- } else if cerr , ok := err .(* connectError ); ok {
192
+ } else if cerr , ok := err .(* ConnectError ); ok {
193
193
if _ , ok := cerr .err .(* NotPreferredError ); ok {
194
194
fallbackConfig = fc
195
195
}
@@ -199,7 +199,7 @@ func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err er
199
199
if ! foundBestServer && fallbackConfig != nil {
200
200
pgConn , err = connect (ctx , config , fallbackConfig , true )
201
201
if pgerr , ok := err .(* PgError ); ok {
202
- err = & connectError { config : config , msg : "server error" , err : pgerr }
202
+ err = & ConnectError { Config : config , msg : "server error" , err : pgerr }
203
203
}
204
204
}
205
205
@@ -211,7 +211,7 @@ func ConnectConfig(octx context.Context, config *Config) (pgConn *PgConn, err er
211
211
err := config .AfterConnect (ctx , pgConn )
212
212
if err != nil {
213
213
pgConn .conn .Close ()
214
- return nil , & connectError { config : config , msg : "AfterConnect error" , err : err }
214
+ return nil , & ConnectError { Config : config , msg : "AfterConnect error" , err : err }
215
215
}
216
216
}
217
217
@@ -283,7 +283,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
283
283
network , address := NetworkAddress (fallbackConfig .Host , fallbackConfig .Port )
284
284
netConn , err := config .DialFunc (ctx , network , address )
285
285
if err != nil {
286
- return nil , & connectError { config : config , msg : "dial error" , err : normalizeTimeoutError (ctx , err )}
286
+ return nil , & ConnectError { Config : config , msg : "dial error" , err : normalizeTimeoutError (ctx , err )}
287
287
}
288
288
289
289
pgConn .conn = netConn
@@ -295,7 +295,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
295
295
pgConn .contextWatcher .Unwatch () // Always unwatch `netConn` after TLS.
296
296
if err != nil {
297
297
netConn .Close ()
298
- return nil , & connectError { config : config , msg : "tls error" , err : normalizeTimeoutError (ctx , err )}
298
+ return nil , & ConnectError { Config : config , msg : "tls error" , err : normalizeTimeoutError (ctx , err )}
299
299
}
300
300
301
301
pgConn .conn = nbTLSConn
@@ -336,7 +336,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
336
336
pgConn .frontend .Send (& startupMsg )
337
337
if err := pgConn .flushWithPotentialWriteReadDeadlock (); err != nil {
338
338
pgConn .conn .Close ()
339
- return nil , & connectError { config : config , msg : "failed to write startup message" , err : normalizeTimeoutError (ctx , err )}
339
+ return nil , & ConnectError { Config : config , msg : "failed to write startup message" , err : normalizeTimeoutError (ctx , err )}
340
340
}
341
341
342
342
for {
@@ -346,7 +346,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
346
346
if err , ok := err .(* PgError ); ok {
347
347
return nil , err
348
348
}
349
- return nil , & connectError { config : config , msg : "failed to receive message" , err : normalizeTimeoutError (ctx , err )}
349
+ return nil , & ConnectError { Config : config , msg : "failed to receive message" , err : normalizeTimeoutError (ctx , err )}
350
350
}
351
351
352
352
switch msg := msg .(type ) {
@@ -359,26 +359,26 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
359
359
err = pgConn .txPasswordMessage (pgConn .config .Password )
360
360
if err != nil {
361
361
pgConn .conn .Close ()
362
- return nil , & connectError { config : config , msg : "failed to write password message" , err : err }
362
+ return nil , & ConnectError { Config : config , msg : "failed to write password message" , err : err }
363
363
}
364
364
case * pgproto3.AuthenticationMD5Password :
365
365
digestedPassword := "md5" + hexMD5 (hexMD5 (pgConn .config .Password + pgConn .config .User )+ string (msg .Salt [:]))
366
366
err = pgConn .txPasswordMessage (digestedPassword )
367
367
if err != nil {
368
368
pgConn .conn .Close ()
369
- return nil , & connectError { config : config , msg : "failed to write password message" , err : err }
369
+ return nil , & ConnectError { Config : config , msg : "failed to write password message" , err : err }
370
370
}
371
371
case * pgproto3.AuthenticationSASL :
372
372
err = pgConn .scramAuth (msg .AuthMechanisms )
373
373
if err != nil {
374
374
pgConn .conn .Close ()
375
- return nil , & connectError { config : config , msg : "failed SASL auth" , err : err }
375
+ return nil , & ConnectError { Config : config , msg : "failed SASL auth" , err : err }
376
376
}
377
377
case * pgproto3.AuthenticationGSS :
378
378
err = pgConn .gssAuth ()
379
379
if err != nil {
380
380
pgConn .conn .Close ()
381
- return nil , & connectError { config : config , msg : "failed GSS auth" , err : err }
381
+ return nil , & ConnectError { Config : config , msg : "failed GSS auth" , err : err }
382
382
}
383
383
case * pgproto3.ReadyForQuery :
384
384
pgConn .status = connStatusIdle
@@ -396,7 +396,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
396
396
return pgConn , nil
397
397
}
398
398
pgConn .conn .Close ()
399
- return nil , & connectError { config : config , msg : "ValidateConnect failed" , err : err }
399
+ return nil , & ConnectError { Config : config , msg : "ValidateConnect failed" , err : err }
400
400
}
401
401
}
402
402
return pgConn , nil
@@ -407,7 +407,7 @@ func connect(ctx context.Context, config *Config, fallbackConfig *FallbackConfig
407
407
return nil , ErrorResponseToPgError (msg )
408
408
default :
409
409
pgConn .conn .Close ()
410
- return nil , & connectError { config : config , msg : "received unexpected message" , err : err }
410
+ return nil , & ConnectError { Config : config , msg : "received unexpected message" , err : err }
411
411
}
412
412
}
413
413
}
0 commit comments