-
Notifications
You must be signed in to change notification settings - Fork 3
/
doc.go
54 lines (39 loc) · 1.37 KB
/
doc.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
/*
Package mongostore follows the Gorilla Session implementation
Reason for creation over using an existing library
When the MongoDB database the sessions were being stored in was not reachable
especially in the event of a database cycle other libraries would not
restablish the database session; this library will.
Example Usage:
func foo(w http.ResponseWriter, r *http.Request) {
// Coonect to MongoDB
dbSess, err := mgo.Dial("localhost")
if err != nil {
panic(err)
}
defer dbSess.Close()
store := mongostore.New(dbSess, "sessions", 3600, true,
[]byte("secret-key"))
// Get a session.
session, err := store.Get(r, "session-key")
if err != nil {
log.Println(err.Error())
}
// Add a value.
session.Values["foo"] = "bar"
// Save.
if err = sessions.Save(r, w); err != nil {
log.Printf("Error saving session: %v", err)
}
fmt.Fprintln(w, "ok")
}
Updating Cookie and MongoDB Expiry Times
if you need your cookies to be rolling and update with every access and
not just modifications you can call:
// Get a session.
session, err := store.GetAndUpdateAccessTime(r, w, "session-key")
instead of
// Get a session.
session, err := store.Get(r, "session-key")
*/
package mongostore