package session import "sync/atomic" type IDMgr struct { count int64 sid int64 } func NewSessionIDMgr() *IDMgr { return &IDMgr{} } // Increment the connection count func (c *IDMgr) Increment() { atomic.AddInt64(&c.count, 1) } // Decrement the connection count func (c *IDMgr) Decrement() { atomic.AddInt64(&c.count, -1) } // Count returns the connection numbers in current func (c *IDMgr) Count() int64 { return atomic.LoadInt64(&c.count) } // Reset the connection service status func (c *IDMgr) Reset() { atomic.StoreInt64(&c.count, 0) atomic.StoreInt64(&c.sid, 0) } // SessionID returns the session id func (c *IDMgr) SessionID() int64 { return atomic.AddInt64(&c.sid, 1) }