golang GO语言session的实现 安装第三方Gorilla web toolkit库/gorilla/sessions

安装Installation
$ go get github.com/gorilla/sessions
参考代码 例子
import (
    "net/http"
    "github.com/gorilla/sessions"
)

var store = sessions.NewCookieStore([]byte("something-very-secret"))

func MyHandler(w http.ResponseWriter, r *http.Request) {
    // Get a session. We're ignoring the error resulted from decoding an
    // existing session: Get() always returns a session, even if empty.
    session, _ := store.Get(r, "session-name")
    // Set some session values.
    session.Values["foo"] = "bar"
    session.Values[42] = 43
    // Save it.
    session.Save(r, w)
}
官方文档: http://www.gorillatoolkit.org/pkg/sessions,国内可能访问不了


发表于:2015-05-01 19:19:14

原文链接(转载请保留): http://www.multisilicon.com/blog/a25342415.html

友情链接: MICROIC
首页