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

Golang securecookie.CodecsFromPairs函数代码示例

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

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



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

示例1: init

func init() {
	a := []byte(os.Getenv("GOTHIC_COOKIE_AUTH"))
	if len(a) == 0 {
		a = securecookie.GenerateRandomKey(64)
	}

	e := []byte(os.Getenv("GOTHIC_COOKIE_ENCRYPT"))
	if len(e) == 0 {
		codecs = securecookie.CodecsFromPairs(a)
	} else {
		codecs = securecookie.CodecsFromPairs(a, e)
	}
}
开发者ID:oov,项目名称:gothic,代码行数:13,代码来源:gothic.go


示例2: NewPGStore

func NewPGStore(dbUrl string, keyPairs ...[]byte) *PGStore {
	db, err := sql.Open("postgres", dbUrl)
	dbmap := &gorp.DbMap{Db: db, Dialect: gorp.PostgresDialect{}}

	dbStore := &PGStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
		DbMap: dbmap,
	}

	if err != nil {
		// Ignore and return nil
		return nil
	}

	// Create table if it doesn't exist
	dbmap.AddTableWithName(Session{}, "http_sessions").SetKeys(true, "Id")
	err = dbmap.CreateTablesIfNotExists()

	if err != nil {
		// Ignore and return nil
		return nil
	}

	return dbStore
}
开发者ID:gernest,项目名称:pgstore,代码行数:29,代码来源:pgstore.go


示例3: init

func init() {
	godotenv.Load()
	redisClient = storage.RedisClient(os.Getenv("REDIS_ADDR"), os.Getenv("REDIS_PASS"))
	translator = t.NewTranslateAdapter(
		[]backend_full.IBackendFull{
			backend_full.NewGoogleTranslator(httpclient.GetHttpClient(), os.Getenv("G_TR_KEY")),
			backend_full.NewYandexTranslator(httpclient.GetHttpClient(), os.Getenv("Y_TR_KEY")),
			//			backend_full.NewBingTranslator(os.Getenv("B_TR_KEY")),
		},
		components.NewChain(2),
	)
	//translator.AddParticular(&particular.AbbyyLingvoLiveTranslator{})
	if "" == os.Getenv("APP_SECRET") {
		os.Setenv("APP_SECRET", string(securecookie.GenerateRandomKey(32)))
	}
	cookieStore = &sessions.CookieStore{
		Codecs: securecookie.CodecsFromPairs([]byte(os.Getenv("APP_SECRET"))),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30 * 10,
			//			Secure:true,
			HttpOnly: true,
		},
	}
}
开发者ID:unitrans,项目名称:unitrans,代码行数:25,代码来源:main.go


示例4: NewRediStore

// NewRediStore returns a new RediStore.
func NewRediStore(size int, network, address, password string, keyPairs ...[]byte) *RediStore {
	return &RediStore{
		// http://godoc.org/github.com/garyburd/redigo/redis#Pool
		Pool: &redis.Pool{
			MaxIdle:     size,
			IdleTimeout: 240 * time.Second,
			Dial: func() (redis.Conn, error) {
				c, err := redis.Dial(network, address)
				if err != nil {
					return nil, err
				}
				if password != "" {
					if _, err := c.Do("AUTH", password); err != nil {
						c.Close()
						return nil, err
					}
				}
				return c, err
			},
			TestOnBorrow: func(c redis.Conn, t time.Time) error {
				_, err := c.Do("PING")
				return err
			},
		},
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: sessionExpire,
		},
	}
}
开发者ID:jsimnz,项目名称:redistore,代码行数:32,代码来源:redistore.go


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


示例6: NewSentinelFailoverStore

// This function returns a new Redis Sentinel store.
//
// Keys are defined in pairs to allow key rotation, but the common case is
// to set a single authentication key and optionally an encryption key.
//
// The first key in a pair is used for authentication and the second for
// encryption. The encryption key can be set to nil or omitted in the last
// pair, but the authentication key is required in all pairs.
//
// It is recommended to use an authentication key with 32 or 64 bytes.
// The encryption key, if set, must be either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256 modes.
//
// Use the convenience function securecookie.GenerateRandomKey() to create
// strong keys.
func NewSentinelFailoverStore(clientConfig SentinelClientConfig,
	keyPairs ...[]byte) *SentinelFailoverStore {
	client := clientConfig.newSentinelFailoverClient()
	s := &SentinelFailoverStore{
		RediStore: &redistore.RediStore{
			Codecs: securecookie.CodecsFromPairs(keyPairs...),
			Options: &sessions.Options{
				Path:   "/",
				MaxAge: 86400 * 30,
			},
			DefaultMaxAge: 60 * 60, // 60 minutes
			//maxLength:     4096,
			//keyPrefix:     "session_",
			//serializer: redistore.GobSerializer{},
		},
		failoverOption: clientConfig,
		FailoverClient: client,
		maxLength:      4096,
		keyPrefix:      "session_",
		serializer:     redistore.GobSerializer{},
	}

	s.SetMaxLength(s.maxLength)
	s.SetKeyPrefix(s.keyPrefix)
	s.SetSerializer(s.serializer)
	s.MaxAge(s.Options.MaxAge)
	return s
}
开发者ID:stackdocker,项目名称:http-session-redis-sentinel-backend,代码行数:43,代码来源:httpsessionstore.go


示例7: New

// New is returns a store object using the provided dal.Connection
func New(connection dal.Connection, database string, collection string, maxAge int,
	ensureTTL bool, keyPairs ...[]byte) nSessions.Store {
	if ensureTTL {
		conn := connection.Clone()
		defer conn.Close()
		db := conn.DB(database)
		c := db.C(collection)
		c.EnsureIndex(dal.Index{
			Key:         []string{"modified"},
			Background:  true,
			Sparse:      true,
			ExpireAfter: time.Duration(maxAge) * time.Second,
		})
	}
	return &dalStore{
		Codecs:     securecookie.CodecsFromPairs(keyPairs...),
		Token:      nSessions.NewCookieToken(),
		connection: connection,
		database:   database,
		collection: collection,
		options: &gSessions.Options{
			MaxAge: maxAge,
		},
	}
}
开发者ID:ShaneBurkhart,项目名称:negroni-sessions,代码行数:26,代码来源:main.go


示例8: NewCookieStore

// NewCookieStore returns a new CookieStore.
//
// Keys are defined in pairs to allow key rotation, but the common case is
// to set a single authentication key and optionally an encryption key.
//
// The first key in a pair is used for authentication and the second for
// encryption. The encryption key can be set to nil or omitted in the last
// pair, but the authentication key is required in all pairs.
//
// It is recommended to use an authentication key with 32 or 64 bytes.
// The encryption key, if set, must be either 16, 24, or 32 bytes to select
// AES-128, AES-192, or AES-256 modes.
//
// Use the convenience function securecookie.GenerateRandomKey() to create
// strong keys.
func NewCookieStore(keyPairs ...[]byte) *CookieStore {
	return &CookieStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
	}
}
开发者ID:Yossibh,项目名称:envdb,代码行数:24,代码来源:store.go


示例9: NewPGStore

// NewPGStore initillizes PGStore with the given keyPairs
func NewPGStore(keyPairs ...[]byte) *PGStore {
	dbStore := &PGStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   settings.App.Session.Path,
			MaxAge: settings.App.Session.MaxAge,
		},
	}
	return dbStore
}
开发者ID:jwulf,项目名称:zedlist,代码行数:11,代码来源:store.go


示例10: GetSessionStore

func (h *RedisStoreHandler) GetSessionStore() sessions.Store {
	return &RedisStore{
		Codecs: securecookie.CodecsFromPairs(h.keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
		storeHandler: h,
	}
}
开发者ID:TheOnly92,项目名称:morioka,代码行数:10,代码来源:sessionredishandler.go


示例11: NewSqliteStoreFromConnection

func NewSqliteStoreFromConnection(db *sql.DB, tableName string, path string, maxAge int, keyPairs ...[]byte) (*SqliteStore, error) {
	// Make sure table name is enclosed.
	tableName = "`" + strings.Trim(tableName, "`") + "`"

	cTableQ := "CREATE TABLE IF NOT EXISTS " +
		tableName + " (id INTEGER PRIMARY KEY, " +
		"session_data LONGBLOB, " +
		"created_on TIMESTAMP DEFAULT 0, " +
		"modified_on TIMESTAMP DEFAULT CURRENT_TIMESTAMP, " +
		"expires_on TIMESTAMP DEFAULT 0);"
	if _, err := db.Exec(cTableQ); err != nil {
		return nil, err
	}

	insQ := "INSERT INTO " + tableName +
		"(id, session_data, created_on, modified_on, expires_on) VALUES (NULL, ?, ?, ?, ?)"
	stmtInsert, stmtErr := db.Prepare(insQ)
	if stmtErr != nil {
		return nil, stmtErr
	}

	delQ := "DELETE FROM " + tableName + " WHERE id = ?"
	stmtDelete, stmtErr := db.Prepare(delQ)
	if stmtErr != nil {
		return nil, stmtErr
	}

	updQ := "UPDATE " + tableName + " SET session_data = ?, created_on = ?, expires_on = ? " +
		"WHERE id = ?"
	stmtUpdate, stmtErr := db.Prepare(updQ)
	if stmtErr != nil {
		return nil, stmtErr
	}

	selQ := "SELECT id, session_data, created_on, modified_on, expires_on from " +
		tableName + " WHERE id = ?"
	stmtSelect, stmtErr := db.Prepare(selQ)
	if stmtErr != nil {
		return nil, stmtErr
	}

	return &SqliteStore{
		db:         db,
		stmtInsert: stmtInsert,
		stmtDelete: stmtDelete,
		stmtUpdate: stmtUpdate,
		stmtSelect: stmtSelect,
		Codecs:     securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   path,
			MaxAge: maxAge,
		},
		table: tableName,
	}, nil
}
开发者ID:starkandwayne,项目名称:shield,代码行数:55,代码来源:sqlitestore.go


示例12: NewRethinkDBStore

func NewRethinkDBStore(rethinkdbSession *gorethink.Session, db, table string, keyPairs ...[]byte) *RethinkDBStore {
	return &RethinkDBStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
		term:             gorethink.Db(db).Table(table),
		rethinkdbSession: rethinkdbSession,
	}
}
开发者ID:miquella,项目名称:rethinkdb_session_store,代码行数:11,代码来源:store.go


示例13: NewDatabaseStore

func NewDatabaseStore(keyPairs ...[]byte) *DatabaseStore {
	dbStore := &DatabaseStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
	}

	return dbStore
}
开发者ID:frazy,项目名称:babou,代码行数:11,代码来源:dbstore.go


示例14: NewDbStore

// NewSessionStore returns a new DbStore.
//
// The path argument is the directory where sessions will be saved. If empty
// it will use os.TempDir().
//
// See NewCookieStore() for a description of the other parameters.
func NewDbStore(age int) *DbStore {
	sessionStore := &DbStore{
		Codecs: securecookie.CodecsFromPairs([]byte("secret")),
		Options: &Options{
			Path:   "/",
			MaxAge: age, //seconds
		},
	}
	go sessionStore.CheckDbSessions()
	return sessionStore
}
开发者ID:mchobits,项目名称:go-blog,代码行数:17,代码来源:db_store.go


示例15: NewRedisStore

// NewRedisStore returns a new RedisStore
func NewRedisStore(pool *redis.Pool, keyPairs ...[]byte) *RedisStore {

	return &RedisStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
		redisPool: pool,
	}
}
开发者ID:armen,项目名称:gapp,代码行数:12,代码来源:redis.go


示例16: NewMemoryStore

func NewMemoryStore(age int) *MemoryStore {
	memoryStore := &MemoryStore{
		Codecs: securecookie.CodecsFromPairs([]byte("secret")),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: age, //default 30 minutes
		},
		Container: make(map[string]*SessionInfo),
	}
	go memoryStore.CheckMemorySessions()
	return memoryStore
}
开发者ID:mchobits,项目名称:go-blog,代码行数:12,代码来源:memory_store.go


示例17: NewDumbMemorySessionStore

// Sessions implemented with a dumb in-memory
// map and no expiration.  Good for local
// development so you don't have to run
// memcached on your laptop just to fire up
// your app and hack away.
func NewDumbMemorySessionStore() *DumbMemoryStore {

	keyPair := []byte("stub")

	return &DumbMemoryStore{
		Codecs: securecookie.CodecsFromPairs(keyPair),
		Options: &sessions.Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
		Data: make(map[string]string),
	}
}
开发者ID:avdienko,项目名称:gorilla-sessions-memcache,代码行数:18,代码来源:gsmstub.go


示例18: NewFilesystemStore

// NewFilesystemStore returns a new FilesystemStore.
//
// The path argument is the directory where sessions will be saved. If empty
// it will use os.TempDir().
//
// See NewCookieStore() for a description of the other parameters.
func NewFilesystemStore(path string, keyPairs ...[]byte) *FilesystemStore {
	if path == "" {
		path = os.TempDir()
	}
	return &FilesystemStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &Options{
			Path:   "/",
			MaxAge: 86400 * 30,
		},
		path: path,
	}
}
开发者ID:BaronSalpeterLLC,项目名称:sessions,代码行数:19,代码来源:store.go


示例19: New

// New returns a new session store.
// See https://github.com/gorilla/sessions/blob/master/store.go for what keyPairs means.
// Especially for dynamostore, keyPairs is be used to authenticate session id.
// Yes, the actual data is stored in DynamoDB table.
func New(dynamodbAPI dynamodbiface.DynamoDBAPI, tableName string, keyPairs ...[]byte) *Store {
	// setting DynamoDB table wrapper
	t := table.New(dynamodbAPI, tableName).WithHashKey(SessionIdHashKeyName, "S")

	s := &Store{
		Table:   t,
		Codecs:  securecookie.CodecsFromPairs(keyPairs...),
		Options: DefaultSessionOpts,
	}
	s.MaxAge(s.Options.MaxAge)

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


示例20: newCookieStore

// 新建cookie存储仓
func newCookieStore(keyPairs ...[]byte) *sessions.CookieStore {
	cs := &sessions.CookieStore{
		Codecs: securecookie.CodecsFromPairs(keyPairs...),
		Options: &sessions.Options{
			Path:     "/",
			MaxAge:   0, // 只存为会话,关闭则失效
			HttpOnly: true,
		},
	}

	cs.MaxAge(cs.Options.MaxAge)
	return cs
}
开发者ID:ying32,项目名称:YingBlog,代码行数:14,代码来源:session.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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