
Security News
Vite Releases Technical Preview of Rolldown-Vite, a Rust-Based Bundler
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
github.com/boj/redistore
A session store backend for gorilla/sessions - src.
Depends on the Redigo Redis library.
go get github.com/boj/redistore
Available on godoc.org.
See the repository for full documentation on underlying interface.
package main
import (
"log"
"net/http"
"github.com/boj/redistore"
"github.com/gorilla/sessions"
)
func main() {
// Fetch new store.
store, err := redistore.NewRediStore(10, "tcp", ":6379", "", "", []byte("secret-key"))
if err != nil {
panic(err)
}
defer store.Close()
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
// Get a session.
session, err := store.Get(r, "session-key")
if err != nil {
log.Println(err.Error())
return
}
// Add a value.
session.Values["foo"] = "bar"
// Save.
if err = sessions.Save(r, w); err != nil {
log.Fatalf("Error saving session: %v", err)
}
// Delete session.
session.Options.MaxAge = -1
if err = sessions.Save(r, w); err != nil {
log.Fatalf("Error saving session: %v", err)
}
})
log.Fatal(http.ListenAndServe(":8080", nil))
}
Sets the maximum length of new sessions. If the length is 0, there is no limit to the size of a session.
store.SetMaxLength(4096)
Sets the prefix for session keys in Redis.
store.SetKeyPrefix("myprefix_")
Sets the serializer for session data. The default is GobSerializer.
store.SetSerializer(redistore.JSONSerializer{})
Sets the maximum age, in seconds, of the session record both in the database and in the browser.
store.SetMaxAge(86400 * 7) // 7 days
Serializes session data to JSON.
type JSONSerializer struct{}
func (s JSONSerializer) Serialize(ss *sessions.Session) ([]byte, error) {
// Implementation
}
func (s JSONSerializer) Deserialize(d []byte, ss *sessions.Session) error {
// Implementation
}
Serializes session data using the gob package.
type GobSerializer struct{}
func (s GobSerializer) Serialize(ss *sessions.Session) ([]byte, error) {
// Implementation
}
func (s GobSerializer) Deserialize(d []byte, ss *sessions.Session) error {
// Implementation
}
This project is licensed under the MIT License - see the LICENSE file for details.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Vite releases Rolldown-Vite, a Rust-based bundler preview offering faster builds and lower memory usage as a drop-in replacement for Vite.
Research
Security News
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Research
Security News
Malicious PyPI package semantic-types steals Solana private keys via transitive dependency installs using monkey patching and blockchain exfiltration.