forked from fasthttp/session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
38 lines (31 loc) · 1.06 KB
/
config.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
package session
import (
"github.com/savsgio/gotils/bytes"
"github.com/valyala/fasthttp"
)
// NewDefaultConfig returns a new default configuration
func NewDefaultConfig() Config {
config := Config{
CookieName: defaultSessionKeyName,
Domain: defaultDomain,
Expiration: defaultExpiration,
GCLifetime: defaultGCLifetime,
Secure: defaultSecure,
SessionIDInURLQuery: defaultSessionIDInURLQuery,
SessionNameInURLQuery: defaultSessionKeyName,
SessionIDInHTTPHeader: defaultSessionIDInHTTPHeader,
SessionNameInHTTPHeader: defaultSessionKeyName,
cookieLen: defaultCookieLen,
}
// default sessionIdGeneratorFunc
config.SessionIDGeneratorFunc = config.defaultSessionIDGenerator
// default isSecureFunc
config.IsSecureFunc = config.defaultIsSecureFunc
return config
}
func (c *Config) defaultSessionIDGenerator() []byte {
return bytes.Rand(make([]byte, c.cookieLen))
}
func (c *Config) defaultIsSecureFunc(ctx *fasthttp.RequestCtx) bool {
return ctx.IsTLS()
}