Add examples
This commit is contained in:
parent
c9d456e6fa
commit
edf6ef79e0
4 changed files with 25 additions and 4 deletions
|
@ -8,8 +8,12 @@ import (
|
|||
|
||||
// Options represents options for the reaper.
|
||||
type Options struct {
|
||||
BucketName []byte
|
||||
BatchSize int
|
||||
// BucketName represents the name of the bucket which contains sessions.
|
||||
BucketName []byte
|
||||
// BatchSize represents the maximum number of sessions which the reaper
|
||||
// process at one time.
|
||||
BatchSize int
|
||||
// CheckInterval represents the interval between the reaper's invocation.
|
||||
CheckInterval time.Duration
|
||||
}
|
||||
|
||||
|
|
|
@ -123,5 +123,19 @@ func Test_reap(t *testing.T) {
|
|||
go reap(db, options, quitC, doneC)
|
||||
time.Sleep(2 * time.Second)
|
||||
Quit(quitC, doneC)
|
||||
|
||||
}
|
||||
|
||||
func ExampleRun() {
|
||||
// Open a Bolt database.
|
||||
db, err := bolt.Open("./sessions.db", 0666)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Close the database when the current function ends.
|
||||
defer db.Close()
|
||||
|
||||
// Invoke a reaper which checks and removes expired sessions periodically.
|
||||
// Terminate the reaper when the current function ends.
|
||||
defer Quit(Run(db, Options{}))
|
||||
}
|
||||
|
|
|
@ -7,8 +7,10 @@ import (
|
|||
|
||||
// Config represents a config for a session store.
|
||||
type Config struct {
|
||||
// SessionOptions represents options for a session.
|
||||
SessionOptions sessions.Options
|
||||
DBOptions Options
|
||||
// DBOptions represents options for a database.
|
||||
DBOptions Options
|
||||
}
|
||||
|
||||
// setDefault sets default to the config.
|
||||
|
|
|
@ -2,5 +2,6 @@ package store
|
|||
|
||||
// Options represents options for a database.
|
||||
type Options struct {
|
||||
// BucketName represents the name of the bucket which contains sessions.
|
||||
BucketName []byte
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue