Run go fmt

This commit is contained in:
Jack Christensen 2022-07-20 06:06:54 -05:00
parent cdd2cc4124
commit 69b99209fb
4 changed files with 20 additions and 19 deletions

View File

@ -67,7 +67,7 @@ type Config struct {
//Congig Options such as getsslpassword function //Congig Options such as getsslpassword function
type ParseConfigOptions struct { type ParseConfigOptions struct {
GetSSLPassword GetSSLPasswordFunc GetSSLPassword GetSSLPasswordFunc
} }
// Copy returns a deep copy of the config that is safe to use and modify. // Copy returns a deep copy of the config that is safe to use and modify.
@ -715,25 +715,25 @@ func configTLS(settings map[string]string, thisHost string, parseConfigOptions P
if x509.IsEncryptedPEMBlock(block) { if x509.IsEncryptedPEMBlock(block) {
// Attempt decryption with pass phrase // Attempt decryption with pass phrase
// NOTE: only supports RSA (PKCS#1) // NOTE: only supports RSA (PKCS#1)
if(sslpassword != ""){ if sslpassword != "" {
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword)) decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
} }
//if sslpassword not provided or has decryption error when use it //if sslpassword not provided or has decryption error when use it
//try to find sslpassword with callback function //try to find sslpassword with callback function
if (sslpassword == "" || decryptedError!= nil) { if sslpassword == "" || decryptedError != nil {
if(parseConfigOptions.GetSSLPassword != nil){ if parseConfigOptions.GetSSLPassword != nil {
sslpassword = parseConfigOptions.GetSSLPassword(context.Background()) sslpassword = parseConfigOptions.GetSSLPassword(context.Background())
} }
if(sslpassword == ""){ if sslpassword == "" {
return nil, fmt.Errorf("unable to find sslpassword") return nil, fmt.Errorf("unable to find sslpassword")
} }
} }
decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword)) decryptedKey, decryptedError = x509.DecryptPEMBlock(block, []byte(sslpassword))
// Should we also provide warning for PKCS#1 needed? // Should we also provide warning for PKCS#1 needed?
if decryptedError != nil { if decryptedError != nil {
return nil, fmt.Errorf("unable to decrypt key: %w", err) return nil, fmt.Errorf("unable to decrypt key: %w", err)
} }
pemBytes := pem.Block{ pemBytes := pem.Block{
Type: "RSA PRIVATE KEY", Type: "RSA PRIVATE KEY",
Bytes: decryptedKey, Bytes: decryptedKey,

View File

@ -1,3 +1,4 @@
//go:build !windows
// +build !windows // +build !windows
package pgconn package pgconn

View File

@ -109,8 +109,8 @@ func Connect(ctx context.Context, connString string) (*PgConn, error) {
return ConnectConfig(ctx, config) return ConnectConfig(ctx, config)
} }
// Connect establishes a connection to a PostgreSQL server using the environment // Connect establishes a connection to a PostgreSQL server using the environment
// and connString (in URL or DSN format) and ParseConfigOptions // and connString (in URL or DSN format) and ParseConfigOptions
// to provide configuration. See documentation for ParseConfig for details. ctx can be used to cancel a connect attempt. // to provide configuration. See documentation for ParseConfig for details. ctx can be used to cancel a connect attempt.
func ConnectWithOptions(ctx context.Context, connString string, parseConfigOptions ParseConfigOptions) (*PgConn, error) { func ConnectWithOptions(ctx context.Context, connString string, parseConfigOptions ParseConfigOptions) (*PgConn, error) {
config, err := ParseConfigWithOptions(connString, parseConfigOptions) config, err := ParseConfigWithOptions(connString, parseConfigOptions)

View File

@ -72,8 +72,8 @@ func TestConnectWithOption(t *testing.T) {
if connString == "" { if connString == "" {
t.Skipf("Skipping due to missing environment variable %v", tt.env) t.Skipf("Skipping due to missing environment variable %v", tt.env)
} }
var sslOptions pgconn.ParseConfigOptions var sslOptions pgconn.ParseConfigOptions
sslOptions.GetSSLPassword = GetSSLPassword sslOptions.GetSSLPassword = GetSSLPassword
conn, err := pgconn.ConnectWithOptions(context.Background(), connString, sslOptions) conn, err := pgconn.ConnectWithOptions(context.Background(), connString, sslOptions)
require.NoError(t, err) require.NoError(t, err)
@ -97,12 +97,12 @@ func TestConnectTLS(t *testing.T) {
var sslOptions pgconn.ParseConfigOptions var sslOptions pgconn.ParseConfigOptions
sslOptions.GetSSLPassword = GetSSLPassword sslOptions.GetSSLPassword = GetSSLPassword
config, err := pgconn.ParseConfigWithOptions(connString, sslOptions) config, err := pgconn.ParseConfigWithOptions(connString, sslOptions)
require.Nil(t, err) require.Nil(t, err)
conn, err = pgconn.ConnectConfig(context.Background(), config) conn, err = pgconn.ConnectConfig(context.Background(), config)
require.NoError(t, err) require.NoError(t, err)
if _, ok := conn.Conn().(*tls.Conn); !ok { if _, ok := conn.Conn().(*tls.Conn); !ok {
t.Error("not a TLS connection") t.Error("not a TLS connection")
} }
@ -2167,5 +2167,5 @@ func Example() {
func GetSSLPassword(ctx context.Context) string { func GetSSLPassword(ctx context.Context) string {
connString := os.Getenv("PGX_SSL_PASSWORD") connString := os.Getenv("PGX_SSL_PASSWORD")
return connString return connString
} }