本文整理汇总了Golang中github.com/gorilla/securecookie.CodecsFromPairs函数的典型用法代码示例。如果您正苦于以下问题:Golang CodecsFromPairs函数的具体用法?Golang CodecsFromPairs怎么用?Golang CodecsFromPairs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CodecsFromPairs函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
}
}
示例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
}
示例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,
},
}
}
示例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,
},
}
}
示例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)
}
}
示例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
}
示例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,
},
}
}
示例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,
},
}
}
示例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
}
示例10: GetSessionStore
func (h *RedisStoreHandler) GetSessionStore() sessions.Store {
return &RedisStore{
Codecs: securecookie.CodecsFromPairs(h.keyPairs...),
Options: &sessions.Options{
Path: "/",
MaxAge: 86400 * 30,
},
storeHandler: h,
}
}
示例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
}
示例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,
}
}
示例13: NewDatabaseStore
func NewDatabaseStore(keyPairs ...[]byte) *DatabaseStore {
dbStore := &DatabaseStore{
Codecs: securecookie.CodecsFromPairs(keyPairs...),
Options: &sessions.Options{
Path: "/",
MaxAge: 86400 * 30,
},
}
return dbStore
}
示例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
}
示例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,
}
}