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

Golang securecookie.DecodeMulti函数代码示例

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

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



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

示例1: 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


示例2: 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


示例3: load

// load reads a file and decodes its content into session.Values.
func (s *FileStore) load(session *Session) error {
	filename := s.path + "session_" + session.ID
	fp, err := os.OpenFile(filename, os.O_RDONLY, 0777)
	if err != nil {
		return err
	}
	defer fp.Close()
	var fdata []byte
	buf := make([]byte, 128)
	for {
		var n int
		n, err = fp.Read(buf[0:])
		fdata = append(fdata, buf[0:n]...)
		if err != nil {
			if err == io.EOF {
				break
			}
			return err
		}
	}
	if err = securecookie.DecodeMulti(session.Name(), string(fdata),
		&session.Values, s.Codecs...); err != nil {
		return err
	}
	return nil
}
开发者ID:mchobits,项目名称:go-blog,代码行数:27,代码来源:file_store.go


示例4: SessionCookieFilter

func SessionCookieFilter(cookieName string, opts *CookieOpts, keyPairs ...[]byte) restful.FilterFunction {
	codecs := securecookie.CodecsFromPairs(keyPairs...)

	return func(req *restful.Request, resp *restful.Response, chain *restful.FilterChain) {

		session := NewSession()
		if cookie, err := req.Request.Cookie(cookieName); err == nil {
			if err = securecookie.DecodeMulti(cookieName, cookie.Value, &session.store, codecs...); err == nil {

			} else {
				logrus.Warn(err)
			}
		} else {
			if err != http.ErrNoCookie {
				logrus.Warn(err)
			}
		}
		req.SetAttribute(AttrSessionKey, session)

		// I don't know how to write cookie in restful, so I use underneath negroni before hook
		resp.ResponseWriter.(negroni.ResponseWriter).Before(func(rw negroni.ResponseWriter) {
			if !session.IsModified() {
				return
			}
			if encoded, err := securecookie.EncodeMulti(cookieName, session.store, codecs...); err == nil {
				cookie := NewCookie(cookieName, encoded, opts)
				http.SetCookie(rw, cookie)
			}
		})

		chain.ProcessFilter(req, resp)
	}
}
开发者ID:iwarsong,项目名称:bearded,代码行数:33,代码来源:session.go


示例5: load

//load fetches a session by ID from the database and decodes its content into session.Values
func (s *Store) load(session *sessions.Session) error {
	ss, err := s.q.GetSessionByKey(session.ID)
	if err != nil {
		return err
	}
	return securecookie.DecodeMulti(session.Name(), string(ss.Data),
		&session.Values, s.codecs...)
}
开发者ID:nguyenducnhaty,项目名称:hero,代码行数:9,代码来源:session_store.go


示例6: load

// load reads a file and decodes its content into session.Values.
func (s *DumbMemoryStore) load(session *sessions.Session) error {

	if err := securecookie.DecodeMulti(session.Name(), string(s.Data[session.ID]),
		&session.Values, s.Codecs...); err != nil {
		return err
	}
	return nil
}
开发者ID:avdienko,项目名称:gorilla-sessions-memcache,代码行数:9,代码来源:gsmstub.go


示例7: load

//load fetches a session by ID from the database and decodes its content into session.Values
func (db *PGStore) load(session *sessions.Session) error {
	s, err := query.GetSessionByKey(session.ID)
	if err != nil {
		return err
	}
	return securecookie.DecodeMulti(session.Name(), string(s.Data),
		&session.Values, db.Codecs...)
}
开发者ID:jwulf,项目名称:zedlist,代码行数:9,代码来源:store.go


示例8: load

// load db and decodes its content into session.Values.
func (s *DbStore) load(session *Session) error {
	sessionInfo := (&model.SessionInfo{Id: session.ID}).GetSessionInfo()
	if err := securecookie.DecodeMulti(session.Name(), sessionInfo.Content,
		&session.Values, s.Codecs...); err != nil {
		return err
	}
	return nil
}
开发者ID:mchobits,项目名称:go-blog,代码行数:9,代码来源:db_store.go


示例9: load

// load fetches a session by ID from the database and decodes its content
// into session.Values
func (db *PGStore) load(session *sessions.Session) error {
	var s Session
	err := db.DbMap.SelectOne(&s, "SELECT * FROM http_sessions WHERE key = $1", session.ID)

	if err := securecookie.DecodeMulti(session.Name(), string(s.Data),
		&session.Values, db.Codecs...); err != nil {
		return err
	}

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


示例10: load

// load reads from redis and decodes its content into session.Values.
func (s *RedisStore) load(session *sessions.Session) error {

	c := s.redisPool.Get()
	defer c.Close()

	encoded, err := redis.String(c.Do("GET", "s:"+session.ID))
	if err != nil {
		return err
	}

	return securecookie.DecodeMulti(session.Name(), encoded, &session.Values, s.Codecs...)
}
开发者ID:armen,项目名称:gapp,代码行数:13,代码来源:redis.go


示例11: sessionValues

// sessionValues extracts session info from the HTTP header. It first looks for a "Authorization" header and then
// it looks for a cookie. It returns a map of the session data.
func sessionValues(r *http.Request) (values map[interface{}]interface{}, err error) {
	err = nil
	// check authorization header
	auth := r.Header.Get("Authorization")
	if strings.HasPrefix(auth, "Cookie") {
		log.Debugf("Authorization header: %v", auth)
		t := strings.Split(auth, " ")
		if len(t) <= 1 {
			err = errors.New("Invalid Authorization header")
		}
		var sessionID string
		if err == nil {
			err = securecookie.DecodeMulti(sessionKey, t[len(t)-1], &sessionID, store.Codecs...)
			log.Debugf("Session ID = %v", sessionID)
		}
		if err == nil {
			if !bson.IsObjectIdHex(sessionID) {
				err = errors.New("Invalid session ID")
			}
		}
		var s mongostore.Session
		if err == nil {
			err = database.C(sessionC).FindId(bson.ObjectIdHex(sessionID)).One(&s)
		}
		if err == nil {
			err = securecookie.DecodeMulti(sessionKey, s.Data, &values, store.Codecs...)
		}
	} else {
		session, err := store.Get(r, sessionKey)
		if err == nil {
			log.Debugf("Cookie found / ID = %v", session.ID)
			values = session.Values
		}
	}
	if err != nil {
		log.Error(err.Error())
	}
	return
}
开发者ID:BlueMasters,项目名称:thymio-captain,代码行数:41,代码来源:main.go


示例12: load

// load reads a file and decodes its content into session.Values.
func (s *FilesystemStore) load(session *Session) error {
	filename := s.path + "session_" + session.ID
	fileMutex.RLock()
	defer fileMutex.RUnlock()
	fdata, err := ioutil.ReadFile(filename)
	if err != nil {
		return err
	}
	if err = securecookie.DecodeMulti(session.Name(), string(fdata),
		&session.Values, s.Codecs...); err != nil {
		return err
	}
	return nil
}
开发者ID:Yossibh,项目名称:envdb,代码行数:15,代码来源:store.go


示例13: 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 *CookieStore) New(r *http.Request, name string) (*Session, error) {
	session := NewSession(s, name)
	session.Options = &(*s.Options)
	session.IsNew = true
	var err error
	if c, errCookie := r.Cookie(name); errCookie == nil {
		err = securecookie.DecodeMulti(name, c.Value, &session.Values,
			s.Codecs...)
		if err == nil {
			session.IsNew = false
		}
	}
	return session, err
}
开发者ID:JoergReinhardt,项目名称:gorilla,代码行数:19,代码来源:store.go


示例14: 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


示例15: load

func (s *RedisStore) load(session *sessions.Session) error {
	c := s.storeHandler.GetRedisConnection()
	defer c.Close()
	c.Send("GET", "morioka_sess_"+session.ID)
	c.Flush()
	data, err := redis.String(c.Receive())
	if err != nil {
		return err
	}
	if err = securecookie.DecodeMulti(session.Name(), data, &session.Values, s.Codecs...); err != nil {
		return err
	}
	return nil
}
开发者ID:TheOnly92,项目名称:morioka,代码行数:14,代码来源:sessionredishandler.go


示例16: 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


示例17: 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


示例18: checkXsrfToken

// Returns true if the XSRF token was correct and an error if needed
func checkXsrfToken(req *http.Request, token []uint8) (bool, error) {
	c := appengine.NewContext(req)

	if token == nil {
		c.Errorf("[xsrf] token is nil")
		return false, nil
	}

	var cookie string
	for _, c := range req.Cookies() {
		if c.Name == "XSRF-TOKEN" {
			cookie = c.Value
		}
	}
	if cookie == "" {
		c.Errorf("[xsrf] no cookie")
		return false, nil
	}

	// Inconsistencies between the script & the cookies
	header := req.Header.Get("X-Xsrf-Token")
	if header != cookie {
		c.Errorf("[xsrf] inconsistency between the header & cookie: %s != %s",
			header, cookie)
		return false, nil
	}

	// Check the token itself
	var unsafeToken []uint8
	err := securecookie.DecodeMulti("XSRF-TOKEN", header, &unsafeToken, xsrfCodecs...)
	if err != nil {
		return false, fmt.Errorf("decode failed: %s", err)
	}
	if len(token) != len(unsafeToken) {
		c.Errorf("[xsrf] length check failed: %d != %d", len(token), len(unsafeToken))
		return false, nil
	}
	for i := range token {
		if token[i] != unsafeToken[i] {
			c.Errorf("[xsrf] character %d is not equal", i)
			return false, nil
		}
	}

	return true, nil
}
开发者ID:ernestoalejo,项目名称:gaelib,代码行数:47,代码来源:router.go


示例19: 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


示例20: New

// New returns a session for the given name without adding it to the registry.
//
// See CookieStore.New().
func (s *FilesystemStore) New(r *http.Request, name string) (*Session, error) {
	session := 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:Yossibh,项目名称:envdb,代码行数:20,代码来源:store.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang securecookie.EncodeMulti函数代码示例发布时间:2022-05-23
下一篇:
Golang securecookie.CodecsFromPairs函数代码示例发布时间: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