Golang Gorilla Sessions Note

Source: Internet
Author: User
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{})}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.