• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang sessions.NewSession函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/gorilla/sessions.NewSession函数的典型用法代码示例。如果您正苦于以下问题:Golang NewSession函数的具体用法?Golang NewSession怎么用?Golang NewSession使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewSession函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: New

// New returns a session for the given name without adding it to the registry.
//
func (s *MemoryStore) 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 {
		Log.Info("MemoryStore reading cookie")
		err = securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
		PanicIf(err)
		if err == nil {
			Log.Info("MemoryStore read cookie success")
			err = s.load(session)
			if err == nil {
				session.IsNew = false
			}
		}
	}
	return session, err
}
开发者ID:mchobits,项目名称:go-blog,代码行数:22,代码来源:memory_store.go


示例17: New

func (m *SqliteStore) 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,
	}
	session.IsNew = true
	var err error
	if cook, errCookie := r.Cookie(name); errCookie == nil {
		err = securecookie.DecodeMulti(name, cook.Value, &session.ID, m.Codecs...)
		if err == nil {
			err = m.load(session)
			if err == nil {
				session.IsNew = false
			} else {
				err = nil
			}
		}
	}
	return session, err
}
开发者ID:starkandwayne,项目名称:shield,代码行数:21,代码来源:sqlitestore.go


示例18: New

func (s *leveldbStore) New(r *http.Request, name string) (*sessions.Session, error) {
	session := sessions.NewSession(s, name)
	opts := *s.options
	// if remember, set MaxAge 1 Year
	opts.MaxAge = 0
	if "on" == r.Form.Get("remember") {
		opts.MaxAge = 86400 * 365
	}
	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 = true
				return session, err
			}
		}
	}
	return session, err
}
开发者ID:Iceyer,项目名称:gutils,代码行数:23,代码来源:leveldb_session.go


示例19: New

func (s *Store) New(r *http.Request, name string) (*sessions.Session, error) {
	session := sessions.NewSession(s, name)

	// Copy default options for new session if we have
	var opts = *DefaultSessionOpts
	if s.Options != nil {
		opts = *s.Options
	}

	session.Options = &opts
	session.IsNew = true
	if c, errCookie := r.Cookie(name); errCookie == nil {
		decodeErr := securecookie.DecodeMulti(name, c.Value, &session.ID, s.Codecs...)
		if decodeErr == nil {
			err := s.load(session)
			if err == nil {
				session.IsNew = false
			}
		}
	}

	return session, nil
}
开发者ID:nabeken,项目名称:gorilla-sessions-dynamodb,代码行数:23,代码来源:dynamostore.go


示例20: New

// New returns a new session for the given name w/o adding it to the registry.
func (db *PGStore) New(r *http.Request, name string) (*sessions.Session, error) {
	session := sessions.NewSession(db, name)
	if session == nil {
		return session, nil
	}
	opts := *db.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, db.Codecs...)
		if err == nil {
			err = db.load(session)
			if err == nil {
				session.IsNew = false
			}
		}
	}

	db.MaxAge(db.Options.MaxAge)

	return session, err
}
开发者ID:starkandwayne,项目名称:shield,代码行数:25,代码来源:pgstore.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang sessions.Save函数代码示例发布时间:2022-05-23
下一篇:
Golang sessions.NewFilesystemStore函数代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap