Documentation ¶
Index ¶
- Constants
- Variables
- func EncodeDel(path string, rev int64) (mutation string, err error)
- func EncodeSet(path, body string, rev int64) (mutation string, err error)
- func GetString(g Getter, path string) (body string)
- func Getdir(g Getter, path string) (entries []string)
- func MustEncodeDel(path string, rev int64) (mutation string)
- func MustEncodeSet(path, body string, rev int64) (mutation string)
- func Walk(g Getter, glob *Glob, f Visitor) (stopped bool)
- type Event
- type Getter
- type Glob
- type GlobError
- type Op
- type Store
- type Visitor
Constants ¶
const ( Missing = int64(-iota) Clobber Dir )
Special values for a revision.
const ErrorPath = "/ctl/err"
const Nop = "nop:"
Variables ¶
var ( ErrBadMutation = errors.New("bad mutation") ErrRevMismatch = errors.New("rev mismatch") ErrBadPath = errors.New("bad path") )
var Any = MustCompileGlob("/**")
var ErrTooLate = errors.New("too late")
Functions ¶
func EncodeDel ¶
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 ¶
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 ¶
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 ¶
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 ¶
MustEncodeDel is like EncodeDel but panics if the mutation cannot be encoded. It simplifies safe initialization of global variables holding mutations.
func MustEncodeSet ¶
MustEncodeSet is like EncodeSet but panics if the mutation cannot be encoded. It simplifies safe initialization of global variables holding mutations.
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) IsDel ¶
Returns true iff the operation represented by `e` deleted a path.
Mutually exclusive with `IsSet` and `IsNop`.
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 ¶
CompileGlob translates pat into a form more convenient for matching against paths in the store.
func MustCompileGlob ¶
MustCompileGlob is like CompileGlob, but it panics if an error occurs, simplifying safe initialization of global variables holding glob patterns.
type Op ¶
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) 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 ¶
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.