NewPGStore should not ignore errors

This commit is contained in:
Marin Bek
2016-02-24 13:29:35 +01:00
parent 646ee39852
commit 22d954a682
3 changed files with 21 additions and 8 deletions

View File

@@ -33,11 +33,11 @@ type Session struct {
// NewPGStore creates a new PGStore instance and a new database/sql pool.
// This will also create in the database the schema needed by pgstore.
func NewPGStore(dbURL string, keyPairs ...[]byte) *PGStore {
func NewPGStore(dbURL string, keyPairs ...[]byte) (*PGStore, error) {
db, err := sql.Open("postgres", dbURL)
if err != nil {
// Ignore and return nil
return nil
return nil, err
}
return NewPGStoreFromPool(db, keyPairs...)
}
@@ -45,7 +45,7 @@ func NewPGStore(dbURL string, keyPairs ...[]byte) *PGStore {
// NewPGStoreFromPool creates a new PGStore instance from an existing
// database/sql pool.
// This will also create in the database the schema needed by pgstore.
func NewPGStoreFromPool(db *sql.DB, keyPairs ...[]byte) *PGStore {
func NewPGStoreFromPool(db *sql.DB, keyPairs ...[]byte) (*PGStore, error) {
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}
dbStore := &PGStore{
@@ -63,10 +63,10 @@ func NewPGStoreFromPool(db *sql.DB, keyPairs ...[]byte) *PGStore {
if err != nil {
// Ignore and return nil
return nil
return nil, err
}
return dbStore
return dbStore, nil
}
// Close closes the database connection