gateway_rpc/servlet/session.go

37 lines
585 B
Go
Raw Normal View History

2018-04-13 08:28:53 +00:00
package servlet
import (
"sync"
2018-04-26 08:00:32 +00:00
"git.loafle.net/commons/server-go"
2018-04-13 08:28:53 +00:00
)
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)
2018-04-26 08:00:32 +00:00
}