gcpdatastore

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 46 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Cloud Datastore

Parity grade: B · SDK cloud.google.com/go/datastore@v1.25.0 · last audited 2026-10-26 (70ee58098)

Coverage

Metric Value
PARITY entries audited 13 (10 ok, 3 partial)
Feature families 8 (3 ok, 5 partial)
Known gaps none
Deferred items 0
Resource leaks clean

More

Documentation

Index

Constants

View Source
const DefaultPort = 8143

DefaultPort is the dedicated gRPC and REST listener's default TCP port (DATASTORE_EMULATOR_HOST).

Variables

View Source
var ErrNilAppContext = errors.New("gcpdatastore: nil app context")

ErrNilAppContext is returned when Init is called with a nil AppContext.

Functions

This section is empty.

Types

type AfterFunc

type AfterFunc func(d time.Duration, f func()) (stop func())

AfterFunc runs f once after d and returns a function that cancels it.

type ConfigProvider

type ConfigProvider interface {
	GetGCPDatastoreSettings() Settings
}

ConfigProvider extracts Datastore configuration from the AppContext Config.

type Handler

type Handler struct {
	Backend *InMemoryBackend

	Port int
	// contains filtered or unexported fields
}

Handler serves the Datastore API on a dedicated gRPC and REST listener.

func NewHandler

func NewHandler(backend *InMemoryBackend) *Handler

NewHandler creates a Handler; callers override Port from Settings.

func (*Handler) Addr

func (h *Handler) Addr() string

Addr returns the bound listener address, or "" before StartWorker.

func (*Handler) ExtractOperation

func (h *Handler) ExtractOperation(*echo.Context) string

ExtractOperation is unused: requests never reach the shared router.

func (*Handler) ExtractResource

func (h *Handler) ExtractResource(*echo.Context) string

ExtractResource is unused: requests never reach the shared router.

func (*Handler) GetSupportedOperations

func (h *Handler) GetSupportedOperations() []string

GetSupportedOperations lists the supported gRPC methods.

func (*Handler) Handler

func (h *Handler) Handler() echo.HandlerFunc

Handler returns a 404 handler; the real API is on the dedicated port.

func (*Handler) MatchPriority

func (h *Handler) MatchPriority() int

MatchPriority is irrelevant because RouteMatcher never matches.

func (*Handler) Name

func (h *Handler) Name() string

Name returns the service name.

func (*Handler) Reset

func (h *Handler) Reset()

Reset clears all state.

func (*Handler) Restore

func (h *Handler) Restore(ctx context.Context, data []byte) error

Restore implements persistence.Persistable by delegating to the backend.

func (*Handler) RouteMatcher

func (h *Handler) RouteMatcher() service.Matcher

RouteMatcher never matches: Datastore runs on its own listener.

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context)

Shutdown stops the listener, forcing a close after a short grace period.

func (*Handler) Snapshot

func (h *Handler) Snapshot(ctx context.Context) []byte

Snapshot implements persistence.Persistable by delegating to the backend.

func (*Handler) StartWorker

func (h *Handler) StartWorker(ctx context.Context) error

StartWorker binds the dedicated listener synchronously so a port conflict is returned to the caller.

type InMemoryBackend

type InMemoryBackend struct {
	// contains filtered or unexported fields
}

InMemoryBackend holds every entity, transaction, reserved id and index under one lock.

func NewInMemoryBackend

func NewInMemoryBackend() *InMemoryBackend

NewInMemoryBackend creates an empty backend that enforces composite indexes.

func (*InMemoryBackend) AllocateIDs

AllocateIDs fills in the ids of incomplete keys.

func (*InMemoryBackend) BeginTransaction

BeginTransaction starts a read-write or read-only transaction.

func (*InMemoryBackend) Commit

Commit applies mutations atomically, optionally inside a transaction.

func (*InMemoryBackend) CreateIndex

CreateIndex registers a composite index in CREATING state; the operation finishes after the build delay.

func (*InMemoryBackend) DeleteIndex

DeleteIndex moves a composite index to DELETING; it is removed when the operation finishes.

func (*InMemoryBackend) ExportEntities

ExportEntities writes the matching entities to the Cloud Storage emulator and returns a finished operation.

func (*InMemoryBackend) GetIndex

GetIndex returns one composite index.

func (*InMemoryBackend) ImportEntities

ImportEntities loads a previous export into the project in one atomic commit.

func (*InMemoryBackend) ListIndexes

ListIndexes pages through a project's composite indexes in creation order.

func (*InMemoryBackend) Lookup

Lookup returns the entities for the requested keys, split into found and missing.

func (*InMemoryBackend) ReserveIDs

ReserveIDs prevents the numeric ids of the given keys from being auto-allocated.

func (*InMemoryBackend) Reset

func (b *InMemoryBackend) Reset()

Reset clears all entities, transactions, reserved ids, indexes and operations.

func (*InMemoryBackend) Restore

func (b *InMemoryBackend) Restore(ctx context.Context, data []byte) error

Restore loads backend state from a snapshot.

func (*InMemoryBackend) Rollback

Rollback discards a transaction.

func (*InMemoryBackend) RunAggregationQuery

RunAggregationQuery computes count, sum and avg over a query.

func (*InMemoryBackend) RunQuery

RunQuery executes a structured or GQL query.

func (*InMemoryBackend) SetClock

func (b *InMemoryBackend) SetClock(now func() time.Time)

SetClock replaces the backend clock.

func (*InMemoryBackend) SetEnforceIndexes

func (b *InMemoryBackend) SetEnforceIndexes(on bool)

SetEnforceIndexes toggles FAILED_PRECONDITION for queries that need a missing composite index.

func (*InMemoryBackend) SetIndexBuild

func (b *InMemoryBackend) SetIndexBuild(delay time.Duration, after AfterFunc)

SetIndexBuild sets how long CreateIndex and DeleteIndex stay not done and the timer that finishes them (nil keeps the wall clock). A zero delay finishes them at once.

func (*InMemoryBackend) SetObjectStore

func (b *InMemoryBackend) SetObjectStore(s ObjectStore)

SetObjectStore wires the Cloud Storage emulator that export and import read and write.

func (*InMemoryBackend) Snapshot

func (b *InMemoryBackend) Snapshot(ctx context.Context) []byte

Snapshot serialises the current state of every entity, reserved ids, indexes and operations. Version history and open transactions are not persisted.

type ObjectStore

type ObjectStore interface {
	ListObjects(bucket, prefix string) ([]string, error)
	ReadObject(bucket, name string) ([]byte, error)
	WriteObject(bucket, name string, data []byte, contentType string) error
}

ObjectStore is the Cloud Storage surface export and import use.

type Provider

type Provider struct{}

Provider implements service.Provider for Google Cloud Datastore. It serves gRPC and REST on its own listener (see Handler.StartWorker) and never matches on the shared AWS router.

func (*Provider) Init

Init creates the backend and handler; the port is bound in StartWorker.

func (*Provider) Name

func (p *Provider) Name() string

Name returns the service provider name.

type Settings

type Settings struct {
	Port int `` //nolint:lll // config struct tags are intentionally verbose
	/* 244-byte string literal not displayed */
	EnforceIndexes bool `` //nolint:lll // config struct tags are intentionally verbose
	/* 254-byte string literal not displayed */
}

Settings holds service-level configuration, embedded in the root CLI as CLI.GCPDatastore.

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings returns the settings used when no ConfigProvider is available.

Jump to

Keyboard shortcuts

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