From a8aadd10dd6bf4e7ef183e8f15a3bc85e7334cfc Mon Sep 17 00:00:00 2001 From: geek Date: Fri, 13 Apr 2018 17:28:53 +0900 Subject: [PATCH] ing --- servlet/session.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 servlet/session.go diff --git a/servlet/session.go b/servlet/session.go new file mode 100644 index 0000000..fc90ff1 --- /dev/null +++ b/servlet/session.go @@ -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) +} \ No newline at end of file