ing
This commit is contained in:
parent
fac4e46be6
commit
a8aadd10dd
35
servlet/session.go
Normal file
35
servlet/session.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package servlet
|
||||
|
||||
import (
|
||||
"git.loafle.net/commons/server-go"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type Session struct {
|
||||
TargetID string
|
||||
ServletCtx server.ServletCtx
|
||||
}
|
||||
|
||||
var sessionPool sync.Pool
|
||||
|
||||
func RetainSession(targetID string, servletCtx server.ServletCtx) *Session {
|
||||
v := sessionPool.Get()
|
||||
var _session *Session
|
||||
if v == nil {
|
||||
_session = &Session{}
|
||||
} else {
|
||||
_session = v.(*Session)
|
||||
}
|
||||
|
||||
_session.TargetID = targetID
|
||||
_session.ServletCtx = servletCtx
|
||||
|
||||
return _session
|
||||
}
|
||||
|
||||
func ReleaseSession(_session *Session) {
|
||||
_session.TargetID = ""
|
||||
_session.ServletCtx = nil
|
||||
|
||||
sessionPool.Put(_session)
|
||||
}
|
Loading…
Reference in New Issue
Block a user