@@ -42,37 +42,27 @@ func NewCookieStore(opt ...Option) session.ManagerStore {
42
42
return & managerStore {
43
43
opts : opts ,
44
44
cookie : cookie ,
45
- pool : sync.Pool {
46
- New : func () interface {} {
47
- return newStore (opts , cookie )
48
- },
49
- },
50
45
}
51
46
}
52
47
53
48
type managerStore struct {
54
49
opts options
55
50
cookie * securecookie.SecureCookie
56
- pool sync.Pool
57
51
}
58
52
59
53
func (s * managerStore ) Create (ctx context.Context , sid string , expired int64 ) (session.Store , error ) {
60
- store := s .pool .Get ().(* store )
61
- store .reset (ctx , sid , expired , nil )
62
- return store , nil
54
+ return newStore (ctx , s , sid , expired , nil ), nil
63
55
}
64
56
65
57
func (s * managerStore ) Update (ctx context.Context , sid string , expired int64 ) (session.Store , error ) {
66
- store := s .pool .Get ().(* store )
67
58
req , ok := session .FromReqContext (ctx )
68
59
if ! ok {
69
60
return nil , nil
70
61
}
71
62
72
63
cookie , err := req .Cookie (s .opts .cookieName )
73
64
if err != nil {
74
- store .reset (ctx , sid , expired , nil )
75
- return store , nil
65
+ return newStore (ctx , s , sid , expired , nil ), nil
76
66
}
77
67
78
68
res , ok := session .FromResContext (ctx )
@@ -88,9 +78,8 @@ func (s *managerStore) Update(ctx context.Context, sid string, expired int64) (s
88
78
if err != nil {
89
79
return nil , err
90
80
}
91
- store .reset (ctx , sid , expired , values )
92
81
93
- return store , nil
82
+ return newStore ( ctx , s , sid , expired , values ) , nil
94
83
}
95
84
96
85
func (s * managerStore ) Delete (ctx context.Context , sid string ) error {
@@ -128,17 +117,14 @@ func (s *managerStore) Check(ctx context.Context, sid string) (bool, error) {
128
117
}
129
118
130
119
func (s * managerStore ) Refresh (ctx context.Context , oldsid , sid string , expired int64 ) (session.Store , error ) {
131
- store := s .pool .Get ().(* store )
132
-
133
120
req , ok := session .FromReqContext (ctx )
134
121
if ! ok {
135
122
return nil , nil
136
123
}
137
124
138
125
cookie , err := req .Cookie (s .opts .cookieName )
139
126
if err != nil {
140
- store .reset (ctx , sid , expired , nil )
141
- return store , nil
127
+ return newStore (ctx , s , sid , expired , nil ), nil
142
128
}
143
129
144
130
var values map [string ]interface {}
@@ -160,19 +146,26 @@ func (s *managerStore) Refresh(ctx context.Context, oldsid, sid string, expired
160
146
return nil , nil
161
147
}
162
148
http .SetCookie (res , cookie )
163
- store .reset (ctx , sid , expired , values )
164
149
165
- return store , nil
150
+ return newStore ( ctx , s , sid , expired , values ) , nil
166
151
}
167
152
168
153
func (s * managerStore ) Close () error {
169
154
return nil
170
155
}
171
156
172
- func newStore (opts options , cookie * securecookie.SecureCookie ) * store {
157
+ func newStore (ctx context.Context , s * managerStore , sid string , expired int64 , values map [string ]interface {}) * store {
158
+ if values == nil {
159
+ values = make (map [string ]interface {})
160
+ }
161
+
173
162
return & store {
174
- opts : opts ,
175
- cookie : cookie ,
163
+ opts : s .opts ,
164
+ cookie : s .cookie ,
165
+ ctx : ctx ,
166
+ sid : sid ,
167
+ expired : expired ,
168
+ values : values ,
176
169
}
177
170
}
178
171
@@ -186,16 +179,6 @@ type store struct {
186
179
values map [string ]interface {}
187
180
}
188
181
189
- func (s * store ) reset (ctx context.Context , sid string , expired int64 , values map [string ]interface {}) {
190
- if values == nil {
191
- values = make (map [string ]interface {})
192
- }
193
- s .ctx = ctx
194
- s .sid = sid
195
- s .expired = expired
196
- s .values = values
197
- }
198
-
199
182
func (s * store ) Context () context.Context {
200
183
return s .ctx
201
184
}
0 commit comments