-
Notifications
You must be signed in to change notification settings - Fork 0
/
service.go
55 lines (42 loc) · 957 Bytes
/
service.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
46
47
48
49
50
51
52
53
54
55
package service
import (
"log"
"github.com/novadinn/social-network/queries"
"github.com/rs/xid"
"github.com/gorilla/sessions"
)
type Service struct {
Queries *queries.Queries
Logger *log.Logger
Store *sessions.CookieStore
Payload map[string]interface{}
}
func New() *Service {
que := queries.New()
// que.Clear()
que = queries.New()
logger := log.Default()
store := sessions.NewCookieStore([]byte("sn-authentication-key"))
store.Options.HttpOnly = true
store.Options.Secure = true
payload := make(map[string]interface{})
return &Service{Queries: que,
Logger: logger,
Store: store,
Payload: payload,
}
}
func (svc *Service) Push(key string, value interface{}) {
svc.Payload[key] = value
}
func (svc *Service) Pop(key string) (interface{}, bool) {
value, ok := svc.Payload[key]
if !ok {
return nil, false
}
delete(svc.Payload, key)
return value, true
}
func genID() string {
return xid.New().String()
}