Documentation ¶
Overview ¶
Package ds describes documents and document stores.
Index ¶
- func DocumentPaths(docs []*Document) []string
- func Path(paths ...interface{}) string
- func PathComponents(path string) []string
- func PathFirst(path string) string
- func PathFrom(path string, n int) string
- func PathLast(path string) string
- func SetLogger(l Logger)
- func Spew(iter DocumentIterator, opt ...SpewOption) (*bytes.Buffer, error)
- func SpewOut(iter DocumentIterator, out io.Writer, opt ...SpewOption) error
- type Collection
- type CollectionIterator
- type ContextLogger
- type Direction
- type Document
- type DocumentIterator
- type DocumentStore
- type DocumentsOption
- type DocumentsOptions
- type ErrPathExists
- type Event
- type EventIterator
- type Events
- type LogLevel
- type Logger
- type Mem
- func (m *Mem) Collections(ctx context.Context, parent string) ([]*Collection, error)
- func (m *Mem) Create(ctx context.Context, path string, b []byte) error
- func (m *Mem) Delete(ctx context.Context, path string) (bool, error)
- func (m *Mem) DeleteAll(ctx context.Context, paths []string) error
- func (m *Mem) DocumentIterator(ctx context.Context, parent string, opt ...DocumentsOption) (DocumentIterator, error)
- func (m *Mem) Documents(ctx context.Context, parent string, opt ...DocumentsOption) ([]*Document, error)
- func (m *Mem) Events(ctx context.Context, path string, index int64, limit int, direction Direction) (EventIterator, error)
- func (m *Mem) EventsAdd(ctx context.Context, path string, data [][]byte) ([]*Event, error)
- func (m *Mem) Exists(ctx context.Context, path string) (bool, error)
- func (m *Mem) Get(ctx context.Context, path string) (*Document, error)
- func (m *Mem) GetAll(ctx context.Context, paths []string) ([]*Document, error)
- func (m *Mem) Now() time.Time
- func (m *Mem) Set(ctx context.Context, path string, b []byte) error
- func (m *Mem) SetTimeNow(nowFn func() time.Time)
- type SpewFormat
- type SpewOption
- type SpewOptions
- type StringSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Path ¶
func Path(paths ...interface{}) string
Path returns a path string from the specified paths or path components. The components can be strings, values with a String() function.
For example,
Path("a", "b") => "/a/b" Path("") => "/" Path("/a/") => "/a" Path("/a//b") => "/a/b"
func PathComponents ¶
PathComponents returns the components of a path.
func Spew ¶
func Spew(iter DocumentIterator, opt ...SpewOption) (*bytes.Buffer, error)
Spew writes DocumentIterator to buffer.
func SpewOut ¶
func SpewOut(iter DocumentIterator, out io.Writer, opt ...SpewOption) error
SpewOut writes DocumentIterator to io.Writer. You need to specify a path or prefix, since listing root is not supported.
Types ¶
type Collection ¶
type Collection struct { // Path for collection. Path string }
Collection is a location for Document's.
type CollectionIterator ¶
type CollectionIterator interface { // Next collection, or nil. Next() (*Collection, error) // Release resources associated with the iterator. Release() }
CollectionIterator is an iterator for Collection's.
func NewCollectionIterator ¶
func NewCollectionIterator(cols []*Collection) CollectionIterator
NewCollectionIterator returns an iterator for a Collection slice.
type ContextLogger ¶
type ContextLogger interface { Debugf(ctx context.Context, format string, args ...interface{}) Infof(ctx context.Context, format string, args ...interface{}) Warningf(ctx context.Context, format string, args ...interface{}) Errorf(ctx context.Context, format string, args ...interface{}) }
ContextLogger interface used in this package with request context.
type Document ¶
type Document struct { // Path of document. Path string `json:"path" msgpack:"p"` // Data ... Data []byte `json:"data" msgpack:"dat"` // CreatedAt (read only). The time at which the document was created. CreatedAt time.Time `json:"cts" msgpack:"cts"` // UpdatedAt (read only). The time at which the document was last changed. UpdatedAt time.Time `json:"uts" msgpack:"uts"` }
Document is data at a path.
func NewDocument ¶
NewDocument creates a datastore document.
type DocumentIterator ¶
type DocumentIterator interface { // Next document, or nil. Next() (*Document, error) // Release resources associated with the iterator. Release() }
DocumentIterator is an iterator for Document's.
func NewDocumentIterator ¶
func NewDocumentIterator(docs ...*Document) DocumentIterator
NewDocumentIterator returns an iterator for a Document slice.
type DocumentStore ¶
type DocumentStore interface { // Create data at path. // ErrPathExists if path already exists. // // Paths can be nested as long as they are even length components. // For example, // // collection1/key1 (OK) // collection1/key1/collection2/key2 (OK) // collection1 (INVALID) // collection1/key1/collection2 (INVALID) // Create(ctx context.Context, path string, b []byte) error // Create or set data at path. // // Paths can be nested as long as they are even length components. // For example, // // collection1/key1 (OK) // collection1/key1/collection2/key2 (OK) // collection1 (INVALID) // collection1/key1/collection2 (INVALID) // Set(ctx context.Context, path string, b []byte) error // Get path. // If not found, returns nil. Get(ctx context.Context, path string) (*Document, error) // GetAll at paths. // If a path is not found, it is ignored. GetAll(ctx context.Context, paths []string) ([]*Document, error) // Exists, if exists at path. Exists(ctx context.Context, path string) (bool, error) // Delete at path. Delete(ctx context.Context, path string) (bool, error) // If a path is not found, it is ignored. DeleteAll(ctx context.Context, paths []string) error // DocumentIterator. DocumentIterator(ctx context.Context, parent string, opt ...DocumentsOption) (DocumentIterator, error) // Documents ... Documents(ctx context.Context, parent string, opt ...DocumentsOption) ([]*Document, error) // Collections are parents of Documents. Collections(ctx context.Context, parent string) ([]*Collection, error) }
DocumentStore is a place for Documents.
type DocumentsOptions ¶
type DocumentsOptions struct { // Prefix to filter on. Prefix string // Index is offset into number of documents. Index int // Limit is number of documents (max) to return. Limit int // NoData to only include only path in Document (no data). NoData bool }
DocumentsOptions ...
func NewDocumentsOptions ¶
func NewDocumentsOptions(opts ...DocumentsOption) DocumentsOptions
NewDocumentsOptions parses DocumentsOptions.
type ErrPathExists ¶
type ErrPathExists struct {
Path string
}
ErrPathExists is trying to set value that already exists.
func (ErrPathExists) Error ¶
func (e ErrPathExists) Error() string
type Event ¶
type Event struct { // Data for event. Data []byte `json:"data" msgpack:"dat" firestore:"data"` // Index for event (read only). Index int64 `json:"idx" msgpack:"idx" firestore:"idx"` // Timestamp (read only). The time at which the event was created. // Firestore sets this to the document create time. Timestamp time.Time `json:"ts" msgpack:"ts" firestore:"-"` }
Event in an event log. If this format changes, you should also change in firestore and other backends that don't directly use this struct on set.
type EventIterator ¶
type EventIterator interface { // Next document, or nil. Next() (*Event, error) // Release resources associated with the iterator. Release() }
EventIterator is an iterator for Event's.
func NewEventIterator ¶
func NewEventIterator(events []*Event) EventIterator
NewEventIterator returns an iterator for a Event slice.
type Events ¶
type Events interface { // EventsAdd appends an event. EventsAdd(ctx context.Context, path string, data [][]byte) ([]*Event, error) // Events from index. Events(ctx context.Context, path string, index int64, limit int, direction Direction) (EventIterator, error) }
Events describes an append only event log.
type Logger ¶
type Logger interface { Debugf(format string, args ...interface{}) Infof(format string, args ...interface{}) Warningf(format string, args ...interface{}) Errorf(format string, args ...interface{}) Fatalf(format string, args ...interface{}) }
Logger interface used in this package.
type Mem ¶
Mem is an in memory DocumentStore implementation.
func (*Mem) Collections ¶
Collections ...
func (*Mem) DocumentIterator ¶
func (m *Mem) DocumentIterator(ctx context.Context, parent string, opt ...DocumentsOption) (DocumentIterator, error)
DocumentIterator ...
func (*Mem) Documents ¶
func (m *Mem) Documents(ctx context.Context, parent string, opt ...DocumentsOption) ([]*Document, error)
Documents ...
func (*Mem) Events ¶
func (m *Mem) Events(ctx context.Context, path string, index int64, limit int, direction Direction) (EventIterator, error)
Events ...
func (*Mem) SetTimeNow ¶
SetTimeNow to use a custom time.Now.
type SpewFormat ¶
type SpewFormat string
SpewFormat is format for Spew.
const ( // SpewFormatDefault ... SpewFormatDefault SpewFormat = "" // SpewFormatTable is in a grid, each entry separated by newlines. SpewFormatTable SpewFormat = "table" // SpewFormatFlat are fields separated by newlines and entries separated by empty lines. SpewFormatFlat SpewFormat = "flat" )
type StringSet ¶
type StringSet struct {
// contains filtered or unexported fields
}
StringSet is a set of strings.
func NewStringSetSplit ¶
NewStringSetSplit creates StringSet for split string.
func NewStringSetWithCapacity ¶
NewStringSetWithCapacity ..