diff options
| author | Thibaut Horel <thibaut.horel@gmail.com> | 2018-12-26 13:20:57 -0500 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2018-12-26 13:20:57 -0500 |
| commit | ed4f6fa1a785e14f39bda9715e3d081fb426ff36 (patch) | |
| tree | b3b9e4095281665a06b96e840133d563224c9fca /store.go | |
| download | id-ed4f6fa1a785e14f39bda9715e3d081fb426ff36.tar.gz | |
Initial commit
Diffstat (limited to 'store.go')
| -rw-r--r-- | store.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/store.go b/store.go new file mode 100644 index 0000000..b744d88 --- /dev/null +++ b/store.go @@ -0,0 +1,35 @@ +package main + +import ( + "database/sql" + "log" + + _ "github.com/lib/pq" +) + +type Session struct { + Id string + UserId string +} + +type SessionStore interface { + Get(id string) (*Session, bool) +} + +type PgSessionStore struct { + *sql.DB + cache map[string]*Session +} + +func NewPgStore() *PgSessionStore { + db, err := sql.Open("postgres", "postgres://auth_master:pass@localhost/authdb") + if err != nil { + log.Panic(err) + } + return &PgSessionStore{db, make(map[string]*Session)} +} + +func (store *PgSessionStore) Get(id string) (*Session, bool) { + s, ok := store.cache[id] + return s, ok +} |
