ConnPoolConfig embeds ConnConfig

scan-io
Jack Christensen 2014-05-19 07:59:51 -05:00
parent 9f50796f1b
commit 6d6fb4561a
3 changed files with 16 additions and 16 deletions

View File

@ -635,8 +635,8 @@ func BenchmarkTimestampTzBinary(b *testing.B) {
} }
func BenchmarkConnPool(b *testing.B) { func BenchmarkConnPool(b *testing.B) {
options := pgx.ConnPoolConfig{MaxConnections: 5} config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 5}
pool, err := pgx.NewConnPool(*defaultConnConfig, options) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
b.Fatalf("Unable to create connection pool: %v", err) b.Fatalf("Unable to create connection pool: %v", err)
} }

View File

@ -6,9 +6,9 @@ import (
) )
type ConnPoolConfig struct { type ConnPoolConfig struct {
ConnConfig
MaxConnections int // max simultaneous connections to use MaxConnections int // max simultaneous connections to use
AfterConnect func(*Conn) error AfterConnect func(*Conn) error
Logger Logger
} }
type ConnPool struct { type ConnPool struct {
@ -27,15 +27,15 @@ type ConnPoolStat struct {
AvailableConnections int // unused live connections AvailableConnections int // unused live connections
} }
// NewConnPool creates a new ConnPool. config are passed through to // NewConnPool creates a new ConnPool. config.ConnConfig is passed through to
// Connect directly. // Connect directly.
func NewConnPool(config ConnConfig, options ConnPoolConfig) (p *ConnPool, err error) { func NewConnPool(config ConnPoolConfig) (p *ConnPool, err error) {
p = new(ConnPool) p = new(ConnPool)
p.config = config p.config = config.ConnConfig
p.maxConnections = options.MaxConnections p.maxConnections = config.MaxConnections
p.afterConnect = options.AfterConnect p.afterConnect = config.AfterConnect
if options.Logger != nil { if config.Logger != nil {
p.logger = options.Logger p.logger = config.Logger
} else { } else {
p.logger = nullLogger("null") p.logger = nullLogger("null")
} }

View File

@ -9,8 +9,8 @@ import (
) )
func createConnPool(t *testing.T, maxConnections int) *pgx.ConnPool { func createConnPool(t *testing.T, maxConnections int) *pgx.ConnPool {
options := pgx.ConnPoolConfig{MaxConnections: maxConnections} config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: maxConnections}
pool, err := pgx.NewConnPool(*defaultConnConfig, options) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
t.Fatalf("Unable to create connection pool: %v", err) t.Fatalf("Unable to create connection pool: %v", err)
} }
@ -24,8 +24,8 @@ func TestNewConnPool(t *testing.T) {
return nil return nil
} }
options := pgx.ConnPoolConfig{MaxConnections: 2, AfterConnect: afterConnect} config := pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 2, AfterConnect: afterConnect}
pool, err := pgx.NewConnPool(*defaultConnConfig, options) pool, err := pgx.NewConnPool(config)
if err != nil { if err != nil {
t.Fatal("Unable to establish connection pool") t.Fatal("Unable to establish connection pool")
} }
@ -43,8 +43,8 @@ func TestNewConnPool(t *testing.T) {
return errAfterConnect return errAfterConnect
} }
options = pgx.ConnPoolConfig{MaxConnections: 2, AfterConnect: afterConnect} config = pgx.ConnPoolConfig{ConnConfig: *defaultConnConfig, MaxConnections: 2, AfterConnect: afterConnect}
pool, err = pgx.NewConnPool(*defaultConnConfig, options) pool, err = pgx.NewConnPool(config)
if err != errAfterConnect { if err != errAfterConnect {
t.Errorf("Expected errAfterConnect but received unexpected: %v", err) t.Errorf("Expected errAfterConnect but received unexpected: %v", err)
} }