本文整理匯總了Golang中code/google/com/p/gorilla/sessions.Session.Name方法的典型用法代碼示例。如果您正苦於以下問題:Golang Session.Name方法的具體用法?Golang Session.Name怎麽用?Golang Session.Name使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類code/google/com/p/gorilla/sessions.Session
的用法示例。
在下文中一共展示了Session.Name方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Save
// Save adds a single session to the response.
func (s *redisStore) Save(r *http.Request, w http.ResponseWriter, session *sessions.Session) error {
var err error
if session.ID == "" {
var i uint64
i, err = NoeqClient.GenOne()
if err != nil {
return err
}
session.ID = strconv.FormatUint(i, 10)
}
if err = s.save(session); err != nil {
return err
}
var encoded string
encoded, err = securecookie.EncodeMulti(session.Name(), &session.ID, s.Codecs...)
if err != nil {
return err
}
options := s.Options
if session.Options != nil {
options = session.Options
}
cookie := &http.Cookie{
Name: session.Name(),
Value: encoded,
Path: options.Path,
Domain: options.Domain,
MaxAge: options.MaxAge,
Secure: options.Secure,
HttpOnly: options.HttpOnly,
}
http.SetCookie(w, cookie)
context.DefaultContext.Clear(r)
return nil
}
示例2: load
func (s *MongoStore) load(session *sessions.Session) error {
mg := &MgSessionTbl{SessionID: []byte(session.ID)}
err := s.DBCollection.Find(bson.M{"sessionid": []byte(session.ID)}).One(mg)
if err == nil {
err = securecookie.DecodeMulti(session.Name(),
string(mg.Encoded), &session.Values, s.Codecs...)
}
return err
}
示例3: save
func (s *MongoStore) save(session *sessions.Session) error {
encoded, err := securecookie.EncodeMulti(session.Name(),
session.Values,
s.Codecs...)
if err != nil {
return err
}
mg := &MgSessionTbl{
Encoded: encoded,
SessionID: []byte(session.ID),
Age: bson.Now(),
}
_, err = s.DBCollection.Upsert(bson.M{"sessionid": session.ID}, mg)
return err
}
示例4: Save
// Save adds a single session to the response.
func (s *DatastoreStore) Save(r *http.Request, w http.ResponseWriter,
session *sessions.Session) error {
if session.ID == "" {
session.ID = string(securecookie.GenerateRandomKey(32))
}
if err := s.save(r, session); err != nil {
return err
}
encoded, err := securecookie.EncodeMulti(session.Name(), session.ID,
s.Codecs...)
if err != nil {
return err
}
http.SetCookie(w, sessions.NewCookie(session.Name(), encoded,
session.Options))
return nil
}
示例5: load
// load reads a file and decodes its content into session.Values.
func (s *redisStore) load(session *sessions.Session) error {
if session.Name() == "remember" {
return nil
}
key := "session:" + session.ID
se, rerr := RedisClient.Get(key)
if rerr != nil {
return rerr
}
ss := se.String()
if ss == "" {
return nil
}
err := securecookie.DecodeMulti(session.Name(), ss, &session.Values, s.Codecs...)
if err != nil {
return err
}
return nil
}
示例6: save
// save writes encoded session.Values to a file.
func (s *redisStore) save(session *sessions.Session) error {
if session.Name() == "remember" {
return nil
}
if len(session.Values) == 0 {
// Don't need to write anything.
return nil
}
encoded, err := securecookie.EncodeMulti(session.Name(), &session.Values, s.Codecs...)
if err != nil {
return err
}
d := make(chan bool)
saves <- &sessionAction{"session:" + session.ID, int64(sessionExpire), encoded, d}
f := <-d
if !f {
return cantSave
}
return nil
}