reaper

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package reaper provides a reaper which checks and removes expired sessions periodically.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Quit

func Quit(quitC chan<- struct{}, doneC <-chan struct{})

Quit terminates the reap goroutine.

func Run

func Run(db *bolt.DB, options Options) (chan<- struct{}, <-chan struct{})

Run invokes a reap function as a goroutine.

Example
// Open a Bolt database.
db, err := bolt.Open("./sessions.db", 0666, nil)
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{}))
Output:

Types

type Options

type Options struct {
	// 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
	// PreDeleteFn register a function to be called before deleting a session.
	// If a non-nil error is returned, the session won't be deleted
	PreDeleteFn func(values map[interface{}]interface{}) error
}

Options represents options for the reaper.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL