mirror of
https://github.com/alexedwards/scs.git
synced 2025-07-13 01:00:17 +02:00
Align indentation in code samples
This commit is contained in:
10
README.md
10
README.md
@ -37,25 +37,25 @@ import (
|
|||||||
var session *scs.Session
|
var session *scs.Session
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Initialize the session manager.
|
// Initialize the session manager.
|
||||||
session = scs.NewSession()
|
session = scs.NewSession()
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/put", putHandler)
|
mux.HandleFunc("/put", putHandler)
|
||||||
mux.HandleFunc("/get", getHandler)
|
mux.HandleFunc("/get", getHandler)
|
||||||
|
|
||||||
// Wrap your handlers with the LoadAndSave() middleware.
|
// Wrap your handlers with the LoadAndSave() middleware.
|
||||||
http.ListenAndServe(":4000", session.LoadAndSave(mux))
|
http.ListenAndServe(":4000", session.LoadAndSave(mux))
|
||||||
}
|
}
|
||||||
|
|
||||||
func putHandler(w http.ResponseWriter, r *http.Request) {
|
func putHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// Store a new key and value in the session data.
|
// Store a new key and value in the session data.
|
||||||
session.Put(r.Context(), "message", "Hello from a session!")
|
session.Put(r.Context(), "message", "Hello from a session!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHandler(w http.ResponseWriter, r *http.Request) {
|
func getHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// Use the GetString helper to retrieve the string value associated with a
|
// Use the GetString helper to retrieve the string value associated with a
|
||||||
// key. The zero value is returned if the key does not exist.
|
// key. The zero value is returned if the key does not exist.
|
||||||
msg := session.GetString(r.Context(), "message")
|
msg := session.GetString(r.Context(), "message")
|
||||||
io.WriteString(w, msg)
|
io.WriteString(w, msg)
|
||||||
}
|
}
|
||||||
|
@ -63,12 +63,12 @@ However, there may be occasions when your use of a session store instance is tra
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
func TestExample(t *testing.T) {
|
func TestExample(t *testing.T) {
|
||||||
store := memstore.New()
|
store := memstore.New()
|
||||||
defer store.StopCleanup()
|
defer store.StopCleanup()
|
||||||
|
|
||||||
session = scs.NewSession()
|
session = scs.NewSession()
|
||||||
session.Store = store
|
session.Store = store
|
||||||
|
|
||||||
// Run test...
|
// Run test...
|
||||||
}
|
}
|
||||||
```
|
```
|
@ -86,18 +86,18 @@ However, there may be occasions when your use of a session store instance is tra
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
func TestExample(t *testing.T) {
|
func TestExample(t *testing.T) {
|
||||||
db, err := sql.Open("mysql", "user:pass@/db?parseTime=true")
|
db, err := sql.Open("mysql", "user:pass@/db?parseTime=true")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
store := mysqlstore.New(db)
|
store := mysqlstore.New(db)
|
||||||
defer store.StopCleanup()
|
defer store.StopCleanup()
|
||||||
|
|
||||||
session = scs.NewSession()
|
session = scs.NewSession()
|
||||||
session.Store = store
|
session.Store = store
|
||||||
|
|
||||||
// Run test...
|
// Run test...
|
||||||
}
|
}
|
||||||
```
|
```
|
@ -86,18 +86,18 @@ However, there may be occasions when your use of a session store instance is tra
|
|||||||
|
|
||||||
```go
|
```go
|
||||||
func TestExample(t *testing.T) {
|
func TestExample(t *testing.T) {
|
||||||
db, err := sql.Open("postgres", "postgres://user:pass@localhost/db")
|
db, err := sql.Open("postgres", "postgres://user:pass@localhost/db")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
defer db.Close()
|
defer db.Close()
|
||||||
|
|
||||||
store := postgresstore.New(db)
|
store := postgresstore.New(db)
|
||||||
defer store.StopCleanup()
|
defer store.StopCleanup()
|
||||||
|
|
||||||
session = scs.NewSession()
|
session = scs.NewSession()
|
||||||
session.Store = store
|
session.Store = store
|
||||||
|
|
||||||
// Run test...
|
// Run test...
|
||||||
}
|
}
|
||||||
```
|
```
|
Reference in New Issue
Block a user