-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsession.go
121 lines (99 loc) · 3.3 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package macross
import (
"net/url"
)
type (
// RawStore is the interface that operates the session data.
RawStore interface {
// Set sets value to given key in session.
Set(interface{}, interface{}) error
// Get gets value by given key in session.
Get(interface{}) interface{}
// Delete deletes a key from session.
Delete(interface{}) error
// ID returns current session ID.
ID() string
// Release releases session resource and save data to provider.
Release(*Context) error
// Flush deletes all session data.
Flush() error
}
// Sessioner is the interface that contains all data for one session process with specific ID.
Sessioner interface {
RawStore
//---------------------------------------------//
// Read returns raw session store by session ID.
Read(string) (RawStore, error)
// Destory deletes a session.
Destory(*Context) error
// RegenerateId regenerates a session store from old session ID to new one.
RegenerateId(*Context) (RawStore, error)
// Count counts and returns number of sessions.
Count() int
// GC calls GC to clean expired sessions.
GC()
}
sessioner struct{}
Flash struct {
FlashNow bool
Ctx *Context
url.Values
ErrorMsg, WarningMsg, InfoMsg, SuccessMsg string
}
)
// Set value to session
func (s *sessioner) Set(key, value interface{}) error { return nil }
// Get value from session by key
func (s *sessioner) Get(key interface{}) interface{} { return nil }
// Delete in session by key
func (s *sessioner) Delete(key interface{}) error { return nil }
// ID get this id of session store
func (s *sessioner) ID() string { return "" }
// Release Implement method, no used.
func (s *sessioner) Release(*Context) error { return nil }
// Flush clear all values in session
func (s *sessioner) Flush() error { return nil }
// Read returns raw session store by session ID.
func (s *sessioner) Read(string) (RawStore, error) { return nil, nil }
// Destory deletes a session.
func (s *sessioner) Destory(*Context) error { return nil }
// RegenerateId regenerates a session store from old session ID to new one.
func (s *sessioner) RegenerateId(*Context) (RawStore, error) { return nil, nil }
// Count counts and returns number of sessions.
func (s *sessioner) Count() int { return 0 }
// GC calls GC to clean expired sessions.
func (s *sessioner) GC() {}
// ___________.____ _____ _________ ___ ___
// \_ _____/| | / _ \ / _____// | \
// | __) | | / /_\ \ \_____ \/ ~ \
// | \ | |___/ | \/ \ Y /
// \___ / |_______ \____|__ /_______ /\___|_ /
// \/ \/ \/ \/ \/
func (f *Flash) set(name, msg string, current ...bool) {
isShow := false
if (len(current) == 0 && FlashNow) || (len(current) > 0 && current[0]) {
isShow = true
}
f.FlashNow = isShow
if isShow {
f.Ctx.Set("Flash", f)
} else {
f.Set(name, msg)
}
}
func (f *Flash) Error(msg string, current ...bool) {
f.ErrorMsg = msg
f.set("error", msg, current...)
}
func (f *Flash) Warning(msg string, current ...bool) {
f.WarningMsg = msg
f.set("warning", msg, current...)
}
func (f *Flash) Info(msg string, current ...bool) {
f.InfoMsg = msg
f.set("info", msg, current...)
}
func (f *Flash) Success(msg string, current ...bool) {
f.SuccessMsg = msg
f.set("success", msg, current...)
}