backend

package
v0.0.0-...-c372385 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2014 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultFileMode contains a secure default file mode
	DefaultFileMode = os.FileMode(0600)
	// DefaultPathMode contains a secure default path mode
	DefaultPathMode = os.FileMode(0700)
)

Variables

This section is empty.

Functions

func FileWalker

func FileWalker(c chan string, prefix string) func(path string, info os.FileInfo, err error) error

FileWalker returns a function which satisfies the filepath.WalkFunc interface. It sends every non-directory file entry down the channel c.

Types

type Backend

type Backend interface {
	Lock()
	RLock()
	RLocker() sync.Locker
	RUnlock()
	Unlock()

	Prepare(key string) error
	Has(key string) bool
	Get(key string) ([]byte, error)
	Set(key string, data []byte) error
	Delete(key string) error
	Scan(prefix string) <-chan string
}

Backend interface defines methods for a storage back end

type FileBackend

type FileBackend struct {
	sync.RWMutex
	Options       Options
	Compress      bool
	CompressLevel int
	Extension     string
	TranslateFile TranslateFileFunc
	TranslatePath TranslatePathFunc
}

FileBackend stores arbitrary data structures on disk as File formatted files.

func NewFileBackend

func NewFileBackend(opt Options) (b *FileBackend, err error)

NewFileBackend initialises a new File storage backend.

func (*FileBackend) Delete

func (b *FileBackend) Delete(key string) (err error)

Delete removes a key from the storage.

func (*FileBackend) FileTranslateSimple

func (b *FileBackend) FileTranslateSimple(key string) string

FileTranslateSimple converts a key to key plus file extension.

func (*FileBackend) Get

func (b *FileBackend) Get(key string) (data []byte, err error)

Get retrieves raw key data from the storage, ready to be unmarshaled.

func (*FileBackend) Has

func (b *FileBackend) Has(key string) bool

Has returns a bool that indicates if the key exists.

func (*FileBackend) Prepare

func (b *FileBackend) Prepare(key string) (err error)

Prepare makes sure the path where the key is stored exists prior to saving it.

func (*FileBackend) Scan

func (b *FileBackend) Scan(prefix string) <-chan string

Scan returns a channel that receives keys that match prefix, in no particular order.

func (*FileBackend) Set

func (b *FileBackend) Set(key string, data []byte) (err error)

Set writes raw key data to the storage, already marshaled.

type Options

type Options struct {
	Path          string
	TranslatePath TranslatePathFunc
	TranslateFile TranslateFileFunc
	FileMode      os.FileMode
	PathMode      os.FileMode
	Extra         map[string]interface{}
}

Options ...

func NewOptions

func NewOptions(dir string) Options

NewOptions creates a new Options structure for the given path, with defaults.

type SqliteBackend

type SqliteBackend struct {
	sync.RWMutex
	Options Options
	DB      *sql.DB
}

func NewSqliteBackend

func NewSqliteBackend(opt Options) (b *SqliteBackend, err error)

func (*SqliteBackend) Delete

func (b *SqliteBackend) Delete(key string) (err error)

Delete removes a row from the table.

func (*SqliteBackend) Get

func (b *SqliteBackend) Get(key string) (data []byte, err error)

Get retrieves raw key data from the storage, ready to be unmarshaled.

func (*SqliteBackend) Has

func (b *SqliteBackend) Has(key string) bool

Has returns a bool that indicates if the key exists.

func (*SqliteBackend) Prepare

func (b *SqliteBackend) Prepare(key string) (err error)

Prepare makes sure the path where the key is stored exists prior to saving it.

func (*SqliteBackend) Scan

func (b *SqliteBackend) Scan(prefix string) <-chan string

Scan returns a channel that receives keys that match prefix, in no particular order.

func (*SqliteBackend) Set

func (b *SqliteBackend) Set(key string, data []byte) (err error)

Set writes raw key data to the storage, already marshaled.

type TranslateFileFunc

type TranslateFileFunc func(key string) string

TranslateFileFunc translates a key to a file path to the key file without its path.

type TranslatePathFunc

type TranslatePathFunc func(key string) []string

TranslatePathFunc translates a key to a directory that contains the key file.

Jump to

Keyboard shortcuts

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