-
Notifications
You must be signed in to change notification settings - Fork 1
/
cookie.go
37 lines (34 loc) · 1.24 KB
/
cookie.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
package db
import (
"github.com/packago/config"
"github.com/packago/cookie"
)
func init() {
NewCookie()
}
func NewCookie() {
var opts cookie.CookieOptions
switch config.File().GetString("environment") {
case "development":
opts = cookie.CookieOptions{
AuthenticationKey: []byte(config.File().GetString("session.development.authenticationKey")),
EncryptionKey: []byte(config.File().GetString("session.development.encryptionKey")),
Domain: config.File().GetString("session.development.domain"),
Path: "/",
MaxAge: config.File().GetInt("session.development.maxAge"),
Secure: false,
}
case "production":
opts = cookie.CookieOptions{
AuthenticationKey: []byte(config.File().GetString("session.production.authenticationKey")),
EncryptionKey: []byte(config.File().GetString("session.production.encryptionKey")),
Domain: config.File().GetString("session.production.domain"),
Path: "/",
MaxAge: config.File().GetInt("session.production.maxAge"),
Secure: true,
}
default:
panic("./config.json environment not set to development or production")
}
cookie.NewCookieStore(config.File().GetString("session.key"), opts)
}