-
Notifications
You must be signed in to change notification settings - Fork 28
/
session.go
45 lines (37 loc) · 986 Bytes
/
session.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package ace
import (
"github.com/plimble/sessions"
)
//SessionOptions session options
type SessionOptions struct {
Path string
Domain string
// MaxAge=0 means no 'Max-Age' attribute specified.
// MaxAge<0 means delete cookie now, equivalently 'Max-Age: 0'.
// MaxAge>0 means Max-Age attribute present and given in seconds.
MaxAge int
Secure bool
HTTPOnly bool
}
//Session use session middleware
func Session(store sessions.Store, options *SessionOptions) HandlerFunc {
var sessionOptions *sessions.Options
if options != nil {
sessionOptions = &sessions.Options{
Path: options.Path,
Domain: options.Domain,
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HTTPOnly,
}
}
manager := sessions.New(512, store, sessionOptions)
return func(c *C) {
c.sessions = manager.GetSessions(c.Request)
defer manager.Close(c.sessions)
c.Writer.Before(func(ResponseWriter) {
c.sessions.Save(c.Writer)
})
c.Next()
}
}