forked from qor/session
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_manager.go
36 lines (29 loc) · 1.25 KB
/
session_manager.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
package session
import (
"net/http"
"github.com/simonedbarber/go-template/html/template"
)
// ManagerInterface session manager interface
type ManagerInterface interface {
// Add value to session data, if value is not string, will marshal it into JSON encoding and save it into session data.
Add(w http.ResponseWriter, req *http.Request, key string, value interface{}) error
// Get value from session data
Get(req *http.Request, key string) string
// Pop value from session data
Pop(w http.ResponseWriter, req *http.Request, key string) string
// Flash add flash message to session data
Flash(w http.ResponseWriter, req *http.Request, message Message) error
// Flashes returns a slice of flash messages from session data
Flashes(w http.ResponseWriter, req *http.Request) []Message
// Load get value from session data and unmarshal it into result
Load(req *http.Request, key string, result interface{}) error
// PopLoad pop value from session data and unmarshal it into result
PopLoad(w http.ResponseWriter, req *http.Request, key string, result interface{}) error
// Middleware returns a new session manager middleware instance.
Middleware(http.Handler) http.Handler
}
// Message message struct
type Message struct {
Message template.HTML
Type string
}