Mercurial > gemma
changeset 199:ddc7ef95c247
Implemented Add of persistent sessions.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 20 Jul 2018 23:06:53 +0200 |
parents | c20e86a3c073 |
children | 8426a92fda00 |
files | auth/persistent.go |
diffstat | 1 files changed, 25 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/auth/persistent.go Fri Jul 20 22:57:38 2018 +0200 +++ b/auth/persistent.go Fri Jul 20 23:06:53 2018 +0200 @@ -103,8 +103,31 @@ } func (pcp *PersistentConnectionPool) Add(token string, session *Session) *Connection { - log.Println("Add: Not implemented, yet.") - return nil + res := make(chan *Connection) + + pcp.cmds <- func(cp *PersistentConnectionPool) { + con := pcp.conns[token] + if con == nil { + con = &Connection{} + pcp.conns[token] = con + } + con.set(session) + err := pcp.db.Update(func(tx *bolt.Tx) error { + b := tx.Bucket(sessionsBucket) + var buf bytes.Buffer + if err := con.serialize(&buf); err != nil { + return err + } + return b.Put([]byte(token), buf.Bytes()) + }) + if err != nil { + log.Printf("error: %v\n", err) + } + res <- con + } + + con := <-res + return con } func (pcp *PersistentConnectionPool) Renew(token string) (string, error) {