Syntax highlighting in README.md

This commit is contained in:
Bruno Bigras 2015-09-13 15:14:50 -04:00
parent 49077d4e04
commit ff2aec5019
1 changed files with 23 additions and 21 deletions

View File

@ -14,31 +14,33 @@ See http://www.gorillatoolkit.org/pkg/sessions for full documentation on underly
### Example ### Example
// Fetch new store. ```go
store := NewPGStore("postgres://user:password@127.0.0.1:5432/database?sslmode=verify-full", []byte("secret-key")) // Fetch new store.
defer store.Close() store := NewPGStore("postgres://user:password@127.0.0.1:5432/database?sslmode=verify-full", []byte("secret-key"))
// Run a background goroutine to clean up expired sessions from the database. defer store.Close()
defer store.StopCleanup(store.Cleanup(time.Minute * 5)) // Run a background goroutine to clean up expired sessions from the database.
defer store.StopCleanup(store.Cleanup(time.Minute * 5))
// Get a session. // Get a session.
session, err = store.Get(req, "session-key") session, err = store.Get(req, "session-key")
if err != nil { if err != nil {
log.Error(err.Error()) log.Error(err.Error())
} }
// Add a value. // Add a value.
session.Values["foo"] = "bar" session.Values["foo"] = "bar"
// Save. // Save.
if err = sessions.Save(req, rsp); err != nil { if err = sessions.Save(req, rsp); err != nil {
t.Fatalf("Error saving session: %v", err) t.Fatalf("Error saving session: %v", err)
} }
// Delete session. // Delete session.
session.Options.MaxAge = -1 session.Options.MaxAge = -1
if err = sessions.Save(req, rsp); err != nil { if err = sessions.Save(req, rsp); err != nil {
t.Fatalf("Error saving session: %v", err) t.Fatalf("Error saving session: %v", err)
} }
```
## Thanks ## Thanks