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 }