mirror of
https://github.com/jackc/pgx.git
synced 2025-05-31 11:42:24 +00:00
fix typos
This commit is contained in:
parent
25935a39b6
commit
1b6543f29c
@ -370,7 +370,7 @@ func ParseConfig(connString string) (*Config, error) {
|
|||||||
case "standby":
|
case "standby":
|
||||||
config.ValidateConnect = ValidateConnectTargetSessionAttrsStandby
|
config.ValidateConnect = ValidateConnectTargetSessionAttrsStandby
|
||||||
case "prefer-standby":
|
case "prefer-standby":
|
||||||
config.ValidateConnect = ValidateConnectTargetSessionAttrsPrefferStandby
|
config.ValidateConnect = ValidateConnectTargetSessionAttrsPreferStandby
|
||||||
config.HasPreferStandbyTargetSessionAttr = true
|
config.HasPreferStandbyTargetSessionAttr = true
|
||||||
case "any":
|
case "any":
|
||||||
// do nothing
|
// do nothing
|
||||||
@ -816,16 +816,16 @@ func ValidateConnectTargetSessionAttrsPrimary(ctx context.Context, pgConn *PgCon
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateConnectTargetSessionAttrsPrimary is an ValidateConnectFunc that implements libpq compatible
|
// ValidateConnectTargetSessionAttrsPreferStandby is an ValidateConnectFunc that implements libpq compatible
|
||||||
// target_session_attrs=prefer-standby.
|
// target_session_attrs=prefer-standby.
|
||||||
func ValidateConnectTargetSessionAttrsPrefferStandby(ctx context.Context, pgConn *PgConn) error {
|
func ValidateConnectTargetSessionAttrsPreferStandby(ctx context.Context, pgConn *PgConn) error {
|
||||||
result := pgConn.ExecParams(ctx, "select pg_is_in_recovery()", nil, nil, nil, nil).Read()
|
result := pgConn.ExecParams(ctx, "select pg_is_in_recovery()", nil, nil, nil, nil).Read()
|
||||||
if result.Err != nil {
|
if result.Err != nil {
|
||||||
return result.Err
|
return result.Err
|
||||||
}
|
}
|
||||||
|
|
||||||
if string(result.Rows[0][0]) != "t" {
|
if string(result.Rows[0][0]) != "t" {
|
||||||
return &preferStanbyNotFoundError{err: errors.New("server is not in hot standby mode")}
|
return &preferStandbyNotFoundError{err: errors.New("server is not in hot standby mode")}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
@ -619,7 +619,7 @@ func TestParseConfig(t *testing.T) {
|
|||||||
Database: "mydb",
|
Database: "mydb",
|
||||||
TLSConfig: nil,
|
TLSConfig: nil,
|
||||||
RuntimeParams: map[string]string{},
|
RuntimeParams: map[string]string{},
|
||||||
ValidateConnect: pgconn.ValidateConnectTargetSessionAttrsPrefferStandby,
|
ValidateConnect: pgconn.ValidateConnectTargetSessionAttrsPreferStandby,
|
||||||
HasPreferStandbyTargetSessionAttr: true,
|
HasPreferStandbyTargetSessionAttr: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -220,19 +220,19 @@ func redactURL(u *url.URL) string {
|
|||||||
return u.String()
|
return u.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
type preferStanbyNotFoundError struct {
|
type preferStandbyNotFoundError struct {
|
||||||
err error
|
err error
|
||||||
safeToRetry bool
|
safeToRetry bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *preferStanbyNotFoundError) Error() string {
|
func (e *preferStandbyNotFoundError) Error() string {
|
||||||
return fmt.Sprintf("standby server not found: %s", e.err.Error())
|
return fmt.Sprintf("standby server not found: %s", e.err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *preferStanbyNotFoundError) SafeToRetry() bool {
|
func (e *preferStandbyNotFoundError) SafeToRetry() bool {
|
||||||
return e.safeToRetry
|
return e.safeToRetry
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *preferStanbyNotFoundError) Unwrap() error {
|
func (e *preferStandbyNotFoundError) Unwrap() error {
|
||||||
return e.err
|
return e.err
|
||||||
}
|
}
|
||||||
|
24
pgconn.go
24
pgconn.go
@ -157,11 +157,18 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err
|
|||||||
break
|
break
|
||||||
} else if pgerr, ok := err.(*PgError); ok {
|
} else if pgerr, ok := err.(*PgError); ok {
|
||||||
err = &connectError{config: config, msg: "server error", err: pgerr}
|
err = &connectError{config: config, msg: "server error", err: pgerr}
|
||||||
if checkPgError(pgerr) {
|
const ERRCODE_INVALID_PASSWORD = "28P01" // wrong password
|
||||||
|
const ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION = "28000" // wrong password or bad pg_hba.conf settings
|
||||||
|
const ERRCODE_INVALID_CATALOG_NAME = "3D000" // db does not exist
|
||||||
|
const ERRCODE_INSUFFICIENT_PRIVILEGE = "42501" // missing connect privilege
|
||||||
|
if pgerr.Code == ERRCODE_INVALID_PASSWORD ||
|
||||||
|
pgerr.Code == ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ||
|
||||||
|
pgerr.Code == ERRCODE_INVALID_CATALOG_NAME ||
|
||||||
|
pgerr.Code == ERRCODE_INSUFFICIENT_PRIVILEGE {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else if cerr, ok := err.(*connectError); ok && config.HasPreferStandbyTargetSessionAttr {
|
} else if cerr, ok := err.(*connectError); ok && config.HasPreferStandbyTargetSessionAttr {
|
||||||
if _, ok := cerr.err.(*preferStanbyNotFoundError); ok {
|
if _, ok := cerr.err.(*preferStandbyNotFoundError); ok {
|
||||||
fallbackConfig = fc
|
fallbackConfig = fc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -173,7 +180,7 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err
|
|||||||
if pgerr, ok := err.(*PgError); ok {
|
if pgerr, ok := err.(*PgError); ok {
|
||||||
err = &connectError{config: config, msg: "server error", err: pgerr}
|
err = &connectError{config: config, msg: "server error", err: pgerr}
|
||||||
}
|
}
|
||||||
config.ValidateConnect = ValidateConnectTargetSessionAttrsPrefferStandby
|
config.ValidateConnect = ValidateConnectTargetSessionAttrsPreferStandby
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -191,17 +198,6 @@ func ConnectConfig(ctx context.Context, config *Config) (pgConn *PgConn, err err
|
|||||||
return pgConn, nil
|
return pgConn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkPgError(pgerr *PgError) bool {
|
|
||||||
const ERRCODE_INVALID_PASSWORD = "28P01" // wrong password
|
|
||||||
const ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION = "28000" // wrong password or bad pg_hba.conf settings
|
|
||||||
const ERRCODE_INVALID_CATALOG_NAME = "3D000" // db does not exist
|
|
||||||
const ERRCODE_INSUFFICIENT_PRIVILEGE = "42501" // missing connect privilege
|
|
||||||
return pgerr.Code == ERRCODE_INVALID_PASSWORD ||
|
|
||||||
pgerr.Code == ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION ||
|
|
||||||
pgerr.Code == ERRCODE_INVALID_CATALOG_NAME ||
|
|
||||||
pgerr.Code == ERRCODE_INSUFFICIENT_PRIVILEGE
|
|
||||||
}
|
|
||||||
|
|
||||||
func expandWithIPs(ctx context.Context, lookupFn LookupFunc, fallbacks []*FallbackConfig) ([]*FallbackConfig, error) {
|
func expandWithIPs(ctx context.Context, lookupFn LookupFunc, fallbacks []*FallbackConfig) ([]*FallbackConfig, error) {
|
||||||
var configs []*FallbackConfig
|
var configs []*FallbackConfig
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user