major changes

This commit is contained in:
ston1th 2018-02-07 21:41:54 +01:00
commit 2b56832843
83 changed files with 7760 additions and 1244 deletions

View file

@ -3,7 +3,7 @@
// license that can be found in the LICENSE file.
/*
Package gorilla/sessions provides cookie and filesystem sessions and
Package sessions provides cookie and filesystem sessions and
infrastructure for custom session backends.
The key features are:
@ -33,7 +33,7 @@ Let's start with an example that shows the sessions API in a nutshell:
// existing session: Get() always returns a session, even if empty.
session, err := store.Get(r, "session-name")
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@ -76,7 +76,7 @@ flashes, call session.Flashes(). Here is an example:
// Get a session.
session, err := store.Get(r, "session-name")
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
@ -118,10 +118,10 @@ so it is easy to register new datatypes for storage in sessions:
}
As it's not possible to pass a raw type as a parameter to a function, gob.Register()
relies on us passing it an empty pointer to the type as a parameter. In the example
above we've passed it a pointer to a struct and a pointer to a custom type
representing a map[string]interface. This will then allow us to serialise/deserialise
values of those types to and from our sessions.
relies on us passing it a value of the desired type. In the example above we've passed
it a pointer to a struct and a pointer to a custom type representing a
map[string]interface. (We could have passed non-pointer values if we wished.) This will
then allow us to serialise/deserialise values of those types to and from our sessions.
Note that because session values are stored in a map[string]interface{}, there's
a need to type-assert data when retrieving it. We'll use the Person struct we registered above:
@ -129,7 +129,7 @@ a need to type-assert data when retrieving it. We'll use the Person struct we re
func MyHandler(w http.ResponseWriter, r *http.Request) {
session, err := store.Get(r, "session-name")
if err != nil {
http.Error(w, err.Error(), 500)
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}