This is a creation in Article, where the information may have evolved or changed.
1. Note that changes are made to the values of the session and must be save to take effect
Login session, _: = store. Get (CTX. Request, "SessionID") timestring: = time. Now (). Format (Common. Defaultmstimelayout) session. values["login_time"] = Timestringsession.save (ctx. Request, CTX)
Logoutfor Key, _: = Range session. Values {Delete (session). Values, key)}session. Save (CTX. Request, CTX)//Delete session attribute also need save
2. In addition to the go basic type, complex object structure storage, must first register
There may also is cases where you want to store a complex datatype within asession, such as a struct. Sessions is serialised using the Encoding/gob Package,so it's easy-register new datatypes for storage in Sessions:imp ORT ("Encoding/gob" "github.com/gorilla/sessions") type person struct {Firstnamestringlastname Stringemailstringageint}type M map[string]interface{}func init () {gob. Register (&person{}) gob. Register (&m{})}