本文整理匯總了Golang中github.com/caixw/lib/go/session.Instance類的典型用法代碼示例。如果您正苦於以下問題:Golang Instance類的具體用法?Golang Instance怎麽用?Golang Instance使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Instance類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: testSession
func testSession(a *assert.Assertion, inst *sess.Instance, w http.ResponseWriter, r *http.Request) {
// 獲取session接口實例
sess, err := inst.StartSession(w, r)
a.NotError(err)
a.NotNil(sess)
// 設置值
sess.Set("uid", 1)
uid, found := sess.Get("uid")
a.True(found)
a.Equal(uid, 1)
// 不存在的值
username := sess.MustGet("username", "abc")
a.Equal(username, "abc")
// 添加值
sess.Set("username", "caixw")
username = sess.MustGet("username", "abc")
a.Equal(username, "caixw")
// 修改值
sess.Set("uid", "2")
uid, found = sess.Get("uid")
a.True(found)
a.Equal(uid, "2")
}
示例2: testSession2
// 測試cookie能否正常使用
func testSession2(a *assert.Assertion, inst *sess.Instance, w http.ResponseWriter, r *http.Request) {
sess, err := inst.StartSession(w, r)
a.NotError(err)
a.NotNil(sess)
uid, found := sess.Get("uid")
a.True(found)
a.Equal(uid, "2")
}
示例3: freeSession2
// 測試freeSession之後,值是否被清空
func freeSession2(a *assert.Assertion, inst *sess.Instance, w http.ResponseWriter, r *http.Request) {
sess, err := inst.StartSession(w, r)
a.NotError(err)
a.NotNil(sess)
defer func() {
a.NotError(sess.Release())
}()
uid, found := sess.Get("uid")
a.False(found)
a.Equal(uid, nil)
}
示例4: freeSession
func freeSession(a *assert.Assertion, inst *sess.Instance, w http.ResponseWriter, r *http.Request) {
err := inst.EndSession(w, r)
a.NotError(err)
}