store

package
v0.3.2-0...-8adec54 Latest Latest
Warning

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

Go to latest
Published: Dec 28, 2013 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Missing = int64(-iota)
	Clobber
	Dir
)

Special values for a revision.

View Source
const ErrorPath = "/ctl/err"
View Source
const Nop = "nop:"

Variables

View Source
var (
	ErrBadMutation = errors.New("bad mutation")
	ErrRevMismatch = errors.New("rev mismatch")
	ErrBadPath     = errors.New("bad path")
)
View Source
var Any = MustCompileGlob("/**")
View Source
var ErrTooLate = errors.New("too late")

Functions

func EncodeDel

func EncodeDel(path string, rev int64) (mutation string, err error)

Returns a mutation that can be applied to a `Store`. The mutation will cause the file at `path` to be deleted iff `rev` is greater than of equal to the file's revision at the time of application, with one exception: if `rev` is Clobber, the file will be deleted unconditionally.

func EncodeSet

func EncodeSet(path, body string, rev int64) (mutation string, err error)

Returns a mutation that can be applied to a `Store`. The mutation will set the contents of the file at `path` to `body` iff `rev` is greater than of equal to the file's revision at the time of application, with one exception: if `rev` is Clobber, the file will be set unconditionally.

func GetString

func GetString(g Getter, path string) (body string)

Retrieves the body stored in `g` at `path` and returns it. If `path` is a directory or does not exist, returns an empty string.

Note, with this function it is impossible to distinguish between an empty string stored at `path`, a missing entry, and a directory. If you need to tell the difference, use `g.Get`.

Also note, this function does not return the revision for `path`. If you need the revision, use `g.Get`.

func Getdir

func Getdir(g Getter, path string) (entries []string)

Returns a list of entries in `g` in the directory at `path`. If `path` is not a directory, returns an empty slice.

Note, with this function it is impossible to distinguish between a string stored at `path` and a missing entry. If you need to tell the difference, use `g.Get`.

func MustEncodeDel

func MustEncodeDel(path string, rev int64) (mutation string)

MustEncodeDel is like EncodeDel but panics if the mutation cannot be encoded. It simplifies safe initialization of global variables holding mutations.

func MustEncodeSet

func MustEncodeSet(path, body string, rev int64) (mutation string)

MustEncodeSet is like EncodeSet but panics if the mutation cannot be encoded. It simplifies safe initialization of global variables holding mutations.

func Walk

func Walk(g Getter, glob *Glob, f Visitor) (stopped bool)

Walk walks the entries in g, calling f for each file that matches glob. Entries are visited in sorted order. If f returns true, Walk will stop visiting entries and return immediately; Walk won't call f again. Walk returns true if f returned true.

Types

type Event

type Event struct {
	Seqn int64
	Path string
	Body string

	// the revision for `Path` as of this event. 0 for a delete event.
	// undefined if the event does not represent a path operation.
	Rev int64

	// the mutation that caused this event
	Mut string

	Err error

	// retrieves values as defined at `Seqn`
	Getter
}

func (Event) Desc

func (e Event) Desc() string

func (Event) IsDel

func (e Event) IsDel() bool

Returns true iff the operation represented by `e` deleted a path.

Mutually exclusive with `IsSet` and `IsNop`.

func (Event) IsNop

func (e Event) IsNop() bool

Returns true iff `e` does not represent a path operation.

Mutually exclusive with `IsSet` and `IsDel`.

func (Event) IsSet

func (e Event) IsSet() bool

Returns true iff the operation represented by `e` set a path.

Mutually exclusive with `IsDel` and `IsNop`.

type Getter

type Getter interface {
	Get(path string) (values []string, rev int64)
	Stat(path string) (ln int32, rev int64)
}

type Glob

type Glob struct {
	Pattern string // original glob pattern
	// contains filtered or unexported fields
}

Glob holds a Unix-style glob pattern in a compiled form for efficient matching against paths.

Glob notation:

  • `?` matches a single char in a single path component
  • `*` matches zero or more chars in a single path component
  • `**` matches zero or more chars in zero or more components
  • any other sequence matches itself

func CompileGlob

func CompileGlob(pat string) (*Glob, error)

CompileGlob translates pat into a form more convenient for matching against paths in the store.

func MustCompileGlob

func MustCompileGlob(pat string) *Glob

MustCompileGlob is like CompileGlob, but it panics if an error occurs, simplifying safe initialization of global variables holding glob patterns.

func (*Glob) Match

func (g *Glob) Match(path string) bool

type GlobError

type GlobError string

func (GlobError) Error

func (e GlobError) Error() string

type Op

type Op struct {
	Seqn int64
	Mut  string
}

Represents an operation to apply to the store at position Seqn.

If Mut is Nop, no change will be made, but an event will still be sent.

type Store

type Store struct {
	Ops     chan<- Op
	Seqns   <-chan int64
	Waiting <-chan int
	// contains filtered or unexported fields
}

Applies mutations sent on Ops in sequence according to field Seqn. Any errors that occur will be written to ErrorPath. Duplicate operations at a given position are sliently ignored.

func New

func New() *Store

Creates a new, empty data store. Mutations will be applied in order, starting at number 1 (number 0 can be thought of as the creation of the store).

func (*Store) Clean

func (st *Store) Clean(seqn int64)

func (*Store) Flush

func (st *Store) Flush()

Apply all operations in the internal queue, even if there are gaps in the sequence (gaps will be treated as no-ops). This is only useful for bootstrapping a store from a point-in-time snapshot of another store.

func (*Store) Get

func (st *Store) Get(path string) (value []string, rev int64)

Gets the value stored at `path`, if any.

If no value is stored at `path`, `rev` will be `Missing` and `value` will be nil.

if `path` is a directory, `rev` will be `Dir` and `value` will be a list of entries.

Otherwise, `rev` is the revision and `value[0]` is the body.

func (*Store) Snap

func (st *Store) Snap() (ver int64, g Getter)

Returns a point-in-time snapshot of the contents of the store.

func (*Store) Stat

func (st *Store) Stat(path string) (int32, int64)

func (*Store) Wait

func (st *Store) Wait(glob *Glob, rev int64) (<-chan Event, error)

Returns a chan that will receive a single event representing the first change made to any file matching glob on or after rev.

If rev is less than any value passed to st.Clean, Wait will return ErrTooLate.

type Visitor

type Visitor func(path, body string, rev int64) (stop bool)

Jump to

Keyboard shortcuts

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