本文整理汇总了Golang中github.com/gorilla/sessions.NewSession函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSession函数的具体用法?Golang NewSession怎么用?Golang NewSession使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewSession函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: New
// New returns a session for the given name without adding it to the registry.
func (m *MongoStore) New(r *http.Request, name string) (
*sessions.Session, error) {
session := sessions.NewSession(m, name)
session.Options = &sessions.Options{
Path: m.Options.Path,
MaxAge: m.Options.MaxAge,
Domain: m.Options.Domain,
Secure: m.Options.Secure,
HttpOnly: m.Options.HttpOnly,
}
session.IsNew = true
var err error
if cook, errToken := m.Token.GetToken(r, name); errToken == nil {
err = securecookie.DecodeMulti(name, cook, &session.ID, m.Codecs...)
if err == nil {
err = m.load(session)
if err == nil {
session.IsNew = false
} else {
err = nil
}
}
}
return session, err
}
示例2: New
func (s *RedisStore) New(r *http.Request, name string) (*sessions.Session, error) {
session := sessions.NewSession(s, name)
session.Options = &(*s.Options)
session.IsNew = true
var err error
if c, errCookie := r.Cookie(name); errCookie == nil {
// TEMP: Check if previous CookieStore
err = securecookie.DecodeMulti(name, c.Value, &session.Values, s.Codecs...)
if err == nil {
err = s.save(session)
if err == nil {
session.IsNew = false
}
} else {
err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
if err == nil {
err = s.load(session)
if err == nil {
session.IsNew = false
}
}
}
}
return session, err
}
示例3: New
func (s *Store) New(r *http.Request, name string) (*sessions.Session, error) {
sess := sessions.NewSession(s, name)
sess.ID = s.id(r)
RLock(sess)
defer RUnlock(sess)
rows, err := s.Query(`
SELECT key, value
FROM `+SqlTableName+`
WHERE id = $1 AND name = $2
`, []byte(sess.ID), name)
if err != nil {
return nil, err
}
defer rows.Close()
for rows.Next() {
var k, v string
if err := rows.Scan(&k, &v); err != nil {
return nil, err
}
sess.Values[k] = v
}
if err := rows.Err(); err != nil {
return nil, err
}
return sess, nil
}
示例4: init
func init() {
sessionSecret = []byte("12345678901234567890123456789012")
sessionStore = sessions.NewCookieStore(sessionSecret)
session = sessions.NewSession(sessionStore, "loginSession")
flag.Parse()
pool = newPool(*redisServer, *redisPassword)
}
示例5: RegenerateSession
// RegenerateSession creates a new session and sets it to current context.
func RegenerateSession(c *web.C) {
o := GetSessionObject(c)
opts := *o.Options
n := sessions.NewSession(o.Store(), o.Name())
n.Options = &opts
n.IsNew = true
c.Env[envKey] = n
o.Options.MaxAge = -1
o.Save(nil, make(noopResponseWriter))
}
示例6: New
func (fs *FakeSessionStore) New(r *http.Request, name string) (*sessions.Session, error) {
if fs.Error {
return nil, fmt.Errorf("Error creating session")
}
s := sessions.NewSession(gothic.Store, name)
s.Values[gothic.SessionName] = `{"session":"exists"}`
s.Values["User"] = "fakeUser"
s.Values["Membership"] = map[string]interface{}{"Groups": []interface{}{"fakeGroup1", "fakeGroup2"}}
s.Options = &sessions.Options{MaxAge: 60}
return s, nil
}
示例7: New
// New fetches the session from this store. name is the name of the cookie
// holding the session ID. Get calls New if the session is not already cached
// in the request's context. This implementation of New never returns a non-nil
// error if client is storing sessions data in a *RamSessions instance.
func (s *RAMStore) New(r *http.Request, name string) (*sessions.Session, error) {
session := sessions.NewSession(s, name)
defaultOptions := *s.Options
session.Options = &defaultOptions
session.IsNew = true
if c, errCookie := r.Cookie(name); errCookie == nil {
session.ID = c.Value
if err := s.load(session); err != nil {
return session, err
}
}
return session, nil
}
示例8: ResetSessionData
// ResetSessionData zero initializes the MockSessionStore and then will copy the input session data into it.
func (store *MockSessionStore) ResetSessionData(data map[string]interface{}, sessionName string) {
store.Options = &sessions.Options{
Path: "/",
MaxAge: 86400 * 30,
}
// Initialize the map to empty.
store.Session = sessions.NewSession(store, sessionName)
for key, value := range data {
store.Session.Values[key] = value
}
store.currentSessionName = sessionName
opts := *store.Options
store.Session.Options = &opts
}
示例9: New
// New returns a session for the given name without adding it to the registry.
func (s *RethinkStore) New(r *http.Request, name string) (*sessions.Session, error) {
var err error
session := sessions.NewSession(s, name)
session.Options = &(*s.Options)
session.IsNew = true
if c, errCookie := r.Cookie(name); errCookie == nil {
err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
if err == nil {
ok, err := s.load(session)
session.IsNew = !(err == nil && ok) // not new if no error and data available
}
}
return session, err
}
示例10: New
// New returns a session for the given name without adding it to the registry.
//
// See gorilla/sessions FilesystemStore.New().
func (s *RediStore) New(r *http.Request, name string) (*sessions.Session, error) {
var err error
session := sessions.NewSession(s, name)
session.Options = &(*s.Options)
session.IsNew = true
if c, errCookie := r.Cookie(name); errCookie == nil {
err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
if err == nil {
err = s.load(session)
if err == nil {
session.IsNew = false
}
}
}
return session, err
}
示例11: New
// New returns a session for the given name without adding it to the registry.
func (d *dalStore) New(r *http.Request, name string) (*gSessions.Session, error) {
var err error
session := gSessions.NewSession(d, name)
options := *d.options
session.Options = &options
session.IsNew = true
if cook, errToken := d.Token.GetToken(r, name); errToken == nil {
err = securecookie.DecodeMulti(name, cook, &session.ID, d.Codecs...)
if err == nil {
ok, err := d.load(session)
session.IsNew = !(err == nil && ok) // not new if no error and data available
}
}
return session, err
}
示例12: New
// New returns a session for the given name without adding it to the registry.
//
// The difference between New() and Get() is that calling New() twice will
// decode the session data twice, while Get() registers and reuses the same
// decoded session after the first call.
func (s *SentinelFailoverStore) New(r *http.Request, name string) (*sessions.Session, error) {
session := sessions.NewSession(s, name)
opts := *s.Options
session.Options = &opts
session.IsNew = true
var err error
if c, errCookie := r.Cookie(name); errCookie == nil {
err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
if err == nil {
err = s.load(session)
if err == nil {
session.IsNew = false
}
}
}
return session, err
}
示例13: New
// New returns a session for the given name without adding it to the registry.
func (m *mongoStore) New(r *http.Request, name string) (*gSessions.Session, error) {
session := gSessions.NewSession(m, name)
session.Options = &gSessions.Options{
Path: m.options.Path,
MaxAge: m.options.MaxAge,
}
session.IsNew = true
var err error
if cook, errToken := m.Token.GetToken(r, name); errToken == nil {
err = securecookie.DecodeMulti(name, cook, &session.ID, m.Codecs...)
if err == nil {
ok, err := m.load(session)
session.IsNew = !(err == nil && ok) // not new if no error and data available
}
}
return session, err
}
示例14: New
// New returns a new session for the given name w/o adding it to the registry.
func (db *DatabaseStore) New(r *http.Request, name string) (*sessions.Session, error) {
session := sessions.NewSession(db, name)
session.Options = &(*db.Options)
session.IsNew = true
var err error
if c, errCookie := r.Cookie(name); errCookie == nil {
err = securecookie.DecodeMulti(name, c.Value, &session.ID, db.Codecs...)
if err == nil {
err = db.load(session)
if err == nil {
session.IsNew = false
}
}
}
return session, err
}
示例15: New
// New returns a session for the given name without adding it to the registry.
//
// See CookieStore.New().
func (s *MemcacheStore) New(r *http.Request, name string) (*sessions.Session,
error) {
session := sessions.NewSession(s, name)
session.Options = &(*s.Options)
session.IsNew = true
var err error
if cookie, errCookie := r.Cookie(name); errCookie == nil {
err = securecookie.DecodeMulti(name, cookie.Value, &session.ID,
s.Codecs...)
if err == nil {
c := appengine.NewContext(r)
err = loadFromMemcache(c, session)
if err == nil {
session.IsNew = false
}
}
}
return session, err
}