aboutsummaryrefslogtreecommitdiffstats
path: root/store.go
diff options
context:
space:
mode:
Diffstat (limited to 'store.go')
-rw-r--r--store.go19
1 files changed, 15 insertions, 4 deletions
diff --git a/store.go b/store.go
index b744d88..55d808b 100644
--- a/store.go
+++ b/store.go
@@ -9,14 +9,20 @@ import (
type Session struct {
Id string
- UserId string
+ UserId int64
}
-type SessionStore interface {
- Get(id string) (*Session, bool)
+type User struct {
+ Id int64
+ UserName string
}
-type PgSessionStore struct {
+type Store interface {
+ GetSession(id string) (*Session, bool)
+ GetUser(id int64) (*User, bool)
+}
+
+type PgStore struct {
*sql.DB
cache map[string]*Session
}
@@ -31,5 +37,10 @@ func NewPgStore() *PgSessionStore {
func (store *PgSessionStore) Get(id string) (*Session, bool) {
s, ok := store.cache[id]
+ if !ok {
+ row := store.QueryRow("SELECT id, user_id FROM session WHERE id = ?", id)
+ var s Session
+ row.Scan(&s.
+ }
return s, ok
}