当前位置: 首页>>代码示例>>Golang>>正文


Golang sessions.NewSession函数代码示例

本文整理汇总了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
}
开发者ID:guilherme-santos,项目名称:mongostore,代码行数:26,代码来源:mongostore.go

示例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
}
开发者ID:TheOnly92,项目名称:morioka,代码行数:25,代码来源:sessionredishandler.go

示例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
}
开发者ID:BurntSushi,项目名称:sqlsess,代码行数:29,代码来源:store.go

示例4: init

func init() {
	sessionSecret = []byte("12345678901234567890123456789012")
	sessionStore = sessions.NewCookieStore(sessionSecret)
	session = sessions.NewSession(sessionStore, "loginSession")

	flag.Parse()
	pool = newPool(*redisServer, *redisPassword)
}
开发者ID:ajem70,项目名称:addaptsoft,代码行数:8,代码来源:main.go

示例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))
}
开发者ID:faultier,项目名称:goji-session,代码行数:11,代码来源:middleware.go

示例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
}
开发者ID:starkandwayne,项目名称:shield,代码行数:11,代码来源:supervisor_test.go

示例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
}
开发者ID:zqg013,项目名称:ramstore,代码行数:17,代码来源:store.go

示例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
}
开发者ID:ArthurHlt,项目名称:cg-deck,代码行数:15,代码来源:testhelpers.go

示例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
}
开发者ID:elithrar,项目名称:rethinkstore,代码行数:15,代码来源:rethinkstore.go

示例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
}
开发者ID:jsimnz,项目名称:redistore,代码行数:19,代码来源:redistore.go

示例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
}
开发者ID:ShaneBurkhart,项目名称:negroni-sessions,代码行数:17,代码来源:main.go

示例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
}
开发者ID:stackdocker,项目名称:http-session-redis-sentinel-backend,代码行数:22,代码来源:httpsessionstore.go

示例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
}
开发者ID:GoIncremental,项目名称:negroni-sessions,代码行数:18,代码来源:main.go

示例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
}
开发者ID:frazy,项目名称:babou,代码行数:19,代码来源:dbstore.go

示例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
}
开发者ID:hnakamur,项目名称:gaesessions,代码行数:22,代码来源:sessions.go


注:本文中的github.com/gorilla/sessions.NewSession函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。