package module
Version: v0.0.0-...-93b26d4 Latest Latest

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

Go to latest
Published: Jul 9, 2021 License: MIT Imports: 17 Imported by: 0



Package firestore implements dstore.Documents backed by firestore.




This section is empty.


This section is empty.


func SetContextLogger

func SetContextLogger(l ContextLogger)

SetContextLogger sets logger for the package.


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.

func NewContextLogger

func NewContextLogger(lev LogLevel) ContextLogger

NewContextLogger ...

type Firestore

type Firestore struct {
	// contains filtered or unexported fields

Firestore is a DocumentStore implemented on Google Cloud Firestore.

func New

func New(uri string, opts ...option.ClientOption) (*Firestore, error)

New creates a Firestore

url := "firestore://chilltest-3297b"
collection := "test"

opts := []option.ClientOption{option.WithCredentialsFile("credentials.json")}
fs, err := New(url, opts...)
if err != nil {

exists, err := fs.Exists(context.TODO(), dstore.Path(collection, "key1"))
if err != nil {
if exists {
	if _, err := fs.Delete(context.TODO(), dstore.Path(collection, "key1")); err != nil {

if err := fs.Create(context.TODO(), dstore.Path(collection, "key1"), dstore.Data([]byte("value1"))); err != nil {

entry, err := fs.Get(context.TODO(), dstore.Path(collection, "key1"))
if err != nil {

fmt.Printf("%s\n", entry.Path)
fmt.Printf("%s\n", entry.Data())


func (*Firestore) Collections

func (f *Firestore) Collections(ctx context.Context, parent string) ([]*dstore.Collection, error)

Collections ...

func (*Firestore) Create

func (f *Firestore) Create(ctx context.Context, path string, values map[string]interface{}) error

Create document.

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)

func (*Firestore) Delete

func (f *Firestore) Delete(ctx context.Context, path string) (bool, error)

Delete ...

func (*Firestore) DeleteAll

func (f *Firestore) DeleteAll(ctx context.Context, paths []string) error

DeleteAll ...

func (*Firestore) DocumentIterator

func (f *Firestore) DocumentIterator(ctx context.Context, parent string, opt ...dstore.Option) (dstore.Iterator, error)

DocumentIterator ...

func (*Firestore) Documents

func (f *Firestore) Documents(ctx context.Context, parent string, opt ...dstore.Option) ([]*dstore.Document, error)

Documents not implemented on Firestore, use DocumentIterator.

func (*Firestore) EventAdd

func (f *Firestore) EventAdd(ctx context.Context, path string, doc events.Document) (int64, error)

func (*Firestore) EventPosition

func (f *Firestore) EventPosition(ctx context.Context, path string) (*events.Position, error)

func (*Firestore) EventPositions

func (f *Firestore) EventPositions(ctx context.Context, paths []string) (map[string]*events.Position, error)

EventPositions returns positions for event logs.

func (*Firestore) Events

func (f *Firestore) Events(ctx context.Context, path string, opt (events.Iterator, error)

Events ...

func (*Firestore) EventsAdd

func (f *Firestore) EventsAdd(ctx context.Context, path string, docs []events.Document) (int64, error)

func (*Firestore) EventsDelete

func (f *Firestore) EventsDelete(ctx context.Context, path string) (bool, error)

EventsDelete removes events.

func (*Firestore) Exists

func (f *Firestore) Exists(ctx context.Context, path string) (bool, error)

Exists returns true if path exists.

func (*Firestore) Get

func (f *Firestore) Get(ctx context.Context, path string) (*dstore.Document, error)

Get ...

func (*Firestore) GetAll

func (f *Firestore) GetAll(ctx context.Context, paths []string) ([]*dstore.Document, error)

GetAll paths.

func (*Firestore) Increment

func (f *Firestore) Increment(ctx context.Context, path string, name string, n int64) (int64, int64, error)

func (*Firestore) Load

func (f *Firestore) Load(ctx context.Context, path string, v interface{}) (bool, error)

Load path into value.

func (*Firestore) Set

func (f *Firestore) Set(ctx context.Context, path string, values map[string]interface{}, opt ...dstore.SetOption) error

Set document. Will create or set, overwriting any existing data.

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)

func (*Firestore) URI

func (f *Firestore) URI() string

URI ...

type LogLevel

type LogLevel int

LogLevel ...

const (
	// DebugLevel ...
	DebugLevel LogLevel = 3
	// InfoLevel ...
	InfoLevel LogLevel = 2
	// WarnLevel ...
	WarnLevel LogLevel = 1
	// ErrLevel ...
	ErrLevel LogLevel = 0

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.

func NewLogger

func NewLogger(lev LogLevel) Logger

NewLogger ...

Jump to

Keyboard shortcuts

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