Initial patch
This commit is contained in:
parent
a407030ba6
commit
272018cf22
10
pgstore.go
10
pgstore.go
|
@ -3,12 +3,12 @@ package pgstore
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/base32"
|
"encoding/base32"
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
|
|
||||||
"github.com/gorilla/securecookie"
|
"github.com/gorilla/securecookie"
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ type PGStore struct {
|
||||||
Codecs []securecookie.Codec
|
Codecs []securecookie.Codec
|
||||||
Options *sessions.Options
|
Options *sessions.Options
|
||||||
Path string
|
Path string
|
||||||
DbPool *sql.DB
|
DbPool *sqlx.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
// PGSession type
|
// PGSession type
|
||||||
|
@ -37,7 +37,7 @@ type PGSession struct {
|
||||||
// NewPGStore creates a new PGStore instance and a new database/sql pool.
|
// NewPGStore creates a new PGStore instance and a new database/sql pool.
|
||||||
// This will also create in the database the schema needed by pgstore.
|
// This will also create in the database the schema needed by pgstore.
|
||||||
func NewPGStore(dbURL string, keyPairs ...[]byte) (*PGStore, error) {
|
func NewPGStore(dbURL string, keyPairs ...[]byte) (*PGStore, error) {
|
||||||
db, err := sql.Open("postgres", dbURL)
|
db, err := sqlx.Open("postgres", dbURL)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Ignore and return nil.
|
// Ignore and return nil.
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -48,7 +48,7 @@ func NewPGStore(dbURL string, keyPairs ...[]byte) (*PGStore, error) {
|
||||||
// NewPGStoreFromPool creates a new PGStore instance from an existing
|
// NewPGStoreFromPool creates a new PGStore instance from an existing
|
||||||
// database/sql pool.
|
// database/sql pool.
|
||||||
// This will also create the database schema needed by pgstore.
|
// This will also create the database schema needed by pgstore.
|
||||||
func NewPGStoreFromPool(db *sql.DB, keyPairs ...[]byte) (*PGStore, error) {
|
func NewPGStoreFromPool(db *sqlx.DB, keyPairs ...[]byte) (*PGStore, error) {
|
||||||
dbStore := &PGStore{
|
dbStore := &PGStore{
|
||||||
Codecs: securecookie.CodecsFromPairs(keyPairs...),
|
Codecs: securecookie.CodecsFromPairs(keyPairs...),
|
||||||
Options: &sessions.Options{
|
Options: &sessions.Options{
|
||||||
|
|
Loading…
Reference in New Issue