diff options
author | Christian Pointner <equinox@helsinki.at> | 2015-12-28 16:20:14 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2015-12-28 16:20:14 (GMT) |
commit | e40cf7868364567c2f6c05ddf1dfa3eff4804a79 (patch) | |
tree | 58d69cda22c77cbd05028556612c62f0791c397c /src | |
parent | 28b7a0a7060416367624171b4d76b451dd3c836c (diff) |
refactoring of session-store, seperate public from private interface
Diffstat (limited to 'src')
-rw-r--r-- | src/helsinki.at/rhimport/session_store.go | 97 |
1 files changed, 50 insertions, 47 deletions
diff --git a/src/helsinki.at/rhimport/session_store.go b/src/helsinki.at/rhimport/session_store.go index e065182..43b5d23 100644 --- a/src/helsinki.at/rhimport/session_store.go +++ b/src/helsinki.at/rhimport/session_store.go @@ -63,12 +63,6 @@ type removeSessionRequest struct { response chan removeSessionResponse } -type SessionStoreChan struct { - newChan chan<- newSessionRequest - getChan chan<- getSessionRequest - removeChan chan<- removeSessionRequest -} - type SessionStore struct { store map[string]map[string]*Session quit chan bool @@ -99,20 +93,6 @@ func (self *SessionStore) new(ctx *ImportContext) (resp newSessionResponse) { return } -func (self *SessionStoreChan) New(ctx *ImportContext) (string, *SessionChan, error) { - res_ch := make(chan newSessionResponse) - req := newSessionRequest{} - req.ctx = ctx - req.response = res_ch - self.newChan <- req - - res := <-res_ch - if res.err != nil { - return "", nil, res.err - } - return res.id, res.session, nil -} - func (self *SessionStore) get(user, id string) (resp getSessionResponse) { if session, exists := self.store[user][id]; exists { resp.session = session.getInterface() @@ -122,21 +102,6 @@ func (self *SessionStore) get(user, id string) (resp getSessionResponse) { return } -func (self *SessionStoreChan) Get(user, id string) (*SessionChan, error) { - res_ch := make(chan getSessionResponse) - req := getSessionRequest{} - req.user = user - req.id = id - req.response = res_ch - self.getChan <- req - - res := <-res_ch - if res.err != nil { - return nil, res.err - } - return res.session, nil -} - func (self *SessionStore) remove(user, id string) (resp removeSessionResponse) { if session, exists := self.store[user][id]; exists { go session.Cleanup() // cleanup could take a while -> don't block all the other stuff @@ -154,18 +119,6 @@ func (self *SessionStore) remove(user, id string) (resp removeSessionResponse) { return } -func (self *SessionStoreChan) Remove(user, id string) error { - res_ch := make(chan removeSessionResponse) - req := removeSessionRequest{} - req.user = user - req.id = id - req.response = res_ch - self.removeChan <- req - - res := <-res_ch - return res.err -} - func (self *SessionStore) dispatchRequests() { defer func() { self.done <- true }() for { @@ -182,6 +135,56 @@ func (self *SessionStore) dispatchRequests() { } } +// ********************************************************* +// Public Interface + +type SessionStoreChan struct { + newChan chan<- newSessionRequest + getChan chan<- getSessionRequest + removeChan chan<- removeSessionRequest +} + +func (self *SessionStoreChan) New(ctx *ImportContext) (string, *SessionChan, error) { + res_ch := make(chan newSessionResponse) + req := newSessionRequest{} + req.ctx = ctx + req.response = res_ch + self.newChan <- req + + res := <-res_ch + if res.err != nil { + return "", nil, res.err + } + return res.id, res.session, nil +} + +func (self *SessionStoreChan) Get(user, id string) (*SessionChan, error) { + res_ch := make(chan getSessionResponse) + req := getSessionRequest{} + req.user = user + req.id = id + req.response = res_ch + self.getChan <- req + + res := <-res_ch + if res.err != nil { + return nil, res.err + } + return res.session, nil +} + +func (self *SessionStoreChan) Remove(user, id string) error { + res_ch := make(chan removeSessionResponse) + req := removeSessionRequest{} + req.user = user + req.id = id + req.response = res_ch + self.removeChan <- req + + res := <-res_ch + return res.err +} + func (self *SessionStore) GetInterface() *SessionStoreChan { ch := &SessionStoreChan{} ch.newChan = self.newChan |