mirror of
https://github.com/fhmq/hmq.git
synced 2026-05-02 14:28:34 +00:00
* modify * update * add acl * add feature * update dockerfile * add deploy * update * update * plugins * plugins * update * update * update * fixed * remove * fixed * add log * update * fixed * update * fix config * add http api * add http api * resp * add config for work chan * update * fixed * update * disable trace * fixed * change acl * fixed * fixed res * dd * dd * ddd * dd * update * fixed * update * add * fixed * update key * add log * update * format * update * update auth * update * update readme * added * update * fixed * fixed * fix * upade * update * update
63 lines
1.0 KiB
Go
63 lines
1.0 KiB
Go
package sessions
|
|
|
|
import (
|
|
"fmt"
|
|
"sync"
|
|
)
|
|
|
|
var _ SessionsProvider = (*memProvider)(nil)
|
|
|
|
func init() {
|
|
Register("mem", NewMemProvider())
|
|
}
|
|
|
|
type memProvider struct {
|
|
st map[string]*Session
|
|
mu sync.RWMutex
|
|
}
|
|
|
|
func NewMemProvider() *memProvider {
|
|
return &memProvider{
|
|
st: make(map[string]*Session),
|
|
}
|
|
}
|
|
|
|
func (this *memProvider) New(id string) (*Session, error) {
|
|
this.mu.Lock()
|
|
defer this.mu.Unlock()
|
|
|
|
this.st[id] = &Session{id: id}
|
|
return this.st[id], nil
|
|
}
|
|
|
|
func (this *memProvider) Get(id string) (*Session, error) {
|
|
this.mu.RLock()
|
|
defer this.mu.RUnlock()
|
|
|
|
sess, ok := this.st[id]
|
|
if !ok {
|
|
return nil, fmt.Errorf("store/Get: No session found for key %s", id)
|
|
}
|
|
|
|
return sess, nil
|
|
}
|
|
|
|
func (this *memProvider) Del(id string) {
|
|
this.mu.Lock()
|
|
defer this.mu.Unlock()
|
|
delete(this.st, id)
|
|
}
|
|
|
|
func (this *memProvider) Save(id string) error {
|
|
return nil
|
|
}
|
|
|
|
func (this *memProvider) Count() int {
|
|
return len(this.st)
|
|
}
|
|
|
|
func (this *memProvider) Close() error {
|
|
this.st = make(map[string]*Session)
|
|
return nil
|
|
}
|