mirror of
https://github.com/alexedwards/scs.git
synced 2025-07-11 00:50:14 +02:00
Alias Session to SessionManager and NewSession to New
This commit is contained in:
@ -35,7 +35,7 @@ import (
|
||||
_ "github.com/lib/pq"
|
||||
)
|
||||
|
||||
var session *scs.Session
|
||||
var sessionManager *scs.SessionManager
|
||||
|
||||
func main() {
|
||||
db, err := sql.Open("postgres", "postgres://user:pass@localhost/db")
|
||||
@ -46,22 +46,22 @@ func main() {
|
||||
|
||||
// Initialize a new session manager and configure it to use PostgreSQL as
|
||||
// the session store.
|
||||
session = scs.NewSession()
|
||||
session.Store = postgresstore.New(db)
|
||||
sessionManager = scs.New()
|
||||
sessionManager.Store = postgresstore.New(db)
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/put", putHandler)
|
||||
mux.HandleFunc("/get", getHandler)
|
||||
|
||||
http.ListenAndServe(":4000", session.LoadAndSave(mux))
|
||||
http.ListenAndServe(":4000", sessionManager.LoadAndSave(mux))
|
||||
}
|
||||
|
||||
func putHandler(w http.ResponseWriter, r *http.Request) {
|
||||
session.Put(r.Context(), "message", "Hello from a session!")
|
||||
sessionManager.Put(r.Context(), "message", "Hello from a session!")
|
||||
}
|
||||
|
||||
func getHandler(w http.ResponseWriter, r *http.Request) {
|
||||
msg := session.GetString(r.Context(), "message")
|
||||
msg := sessionManager.GetString(r.Context(), "message")
|
||||
io.WriteString(w, msg)
|
||||
}
|
||||
```
|
||||
@ -95,8 +95,8 @@ func TestExample(t *testing.T) {
|
||||
store := postgresstore.New(db)
|
||||
defer store.StopCleanup()
|
||||
|
||||
session = scs.NewSession()
|
||||
session.Store = store
|
||||
sessionManager = scs.New()
|
||||
sessionManager.Store = store
|
||||
|
||||
// Run test...
|
||||
}
|
||||
|
Reference in New Issue
Block a user