store

package
v0.0.0-...-6e31670 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package store contains functionality to store objects.

Index

Constants

This section is empty.

Variables

View Source
var TimeNow = time.Now

TimeNow is stubbed for testing.

Functions

func MutateLocation

func MutateLocation(src, dst *resources.Location) error

MutateLocation applies mutable, non-empty field mutations from the src to dst Location.

func MutateRule

func MutateRule(src, dst *resources.Rule) error

MutateRule applies mutable, non-empty field mutations from the src to dst Rule.

func MutateSensorRequest

func MutateSensorRequest(src, dst *resources.SensorRequest) error

MutateSensorRequest applies mutable, non-empty field mutations from the src to dst SensorRequest.

func NewGCDClient

func NewGCDClient(ctx context.Context, projectID, credFile string) (*datastore.Client, error)

NewGCDClient initializes a new Google Cloud Datastore Client. Follow these instructions to set up application credentials: https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually.

func RunTestSuite

func RunTestSuite(t *testing.T, builder func() (Store, error))

RunTestSuite runs all generic store tests.

The tests use the provided builder to instantiate a Store. The builder is expected to always return a valid Store.

Types

type DataStore

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

DataStore represents a Google Cloud Datastore implementation of a Store.

func NewDataStore

func NewDataStore(client *datastore.Client) *DataStore

NewDataStore returns a new DataStore.

func (*DataStore) AddLocation

func (s *DataStore) AddLocation(ctx context.Context, l *resources.Location) error

AddLocation adds the given location.

func (*DataStore) AddRule

func (s *DataStore) AddRule(ctx context.Context, r *resources.Rule) error

AddRule adds the given rule.

func (*DataStore) AddSensorMessage

func (s *DataStore) AddSensorMessage(ctx context.Context, m *resources.SensorMessage) error

AddSensorMessage adds the given sensor message.

func (*DataStore) AddSensorRequest

func (s *DataStore) AddSensorRequest(ctx context.Context, r *resources.SensorRequest) error

AddSensorRequest adds the given sensor request.

func (*DataStore) Close

func (s *DataStore) Close() error

Close Datastore client connection.

func (*DataStore) DeleteLocation

func (s *DataStore) DeleteLocation(ctx context.Context, name string) error

DeleteLocation deletes the given location.

func (*DataStore) DeleteRule

func (s *DataStore) DeleteRule(ctx context.Context, id int64) error

DeleteRule deletes the given rule.

func (*DataStore) DeleteSensorRequest

func (s *DataStore) DeleteSensorRequest(ctx context.Context, id string) error

DeleteSensorRequest removes the given sensor request.

func (*DataStore) GetLocation

func (s *DataStore) GetLocation(ctx context.Context, name string) (*resources.Location, error)

GetLocation gets the location with the given name.

func (*DataStore) GetSensorRequest

func (s *DataStore) GetSensorRequest(ctx context.Context, id string) (*resources.SensorRequest, error)

GetSensorRequest gets the sensor request with the given ID.

func (*DataStore) ListLocations

func (s *DataStore) ListLocations(ctx context.Context) ([]*resources.Location, error)

ListLocations list all locations, ordered by name.

func (*DataStore) ListRules

func (s *DataStore) ListRules(ctx context.Context, ids []int64) ([]*resources.Rule, error)

ListRules lists the rules with the given rule IDs, following the same order. If `ids` is nil, lists all rules, ordered by ID.

func (*DataStore) ModifyLocation

func (s *DataStore) ModifyLocation(ctx context.Context, l *resources.Location) error

ModifyLocation modifies an existing location with the provided location.

func (*DataStore) ModifyRule

func (s *DataStore) ModifyRule(ctx context.Context, r *resources.Rule) error

ModifyRule modifies an existing rule with the provided rule.

func (*DataStore) ModifySensorRequest

func (s *DataStore) ModifySensorRequest(ctx context.Context, r *resources.SensorRequest) error

ModifySensorRequest modifies an existing sensor request with the provided sensor request.

type MemoryStore

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

MemoryStore represents a memory Store implementation.

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns a MemoryStore.

func (*MemoryStore) AddLocation

func (s *MemoryStore) AddLocation(ctx context.Context, l *resources.Location) error

AddLocation adds a Location to the store.

func (*MemoryStore) AddRule

func (s *MemoryStore) AddRule(ctx context.Context, r *resources.Rule) error

AddRule adds a Rule to the store.

func (*MemoryStore) AddSensorMessage

func (s *MemoryStore) AddSensorMessage(ctx context.Context, m *resources.SensorMessage) error

AddSensorMessage adds a sensor message.

func (*MemoryStore) AddSensorRequest

func (s *MemoryStore) AddSensorRequest(ctx context.Context, r *resources.SensorRequest) error

AddSensorRequest adds a sensor request.

func (*MemoryStore) DeleteLocation

func (s *MemoryStore) DeleteLocation(ctx context.Context, name string) error

DeleteLocation deletes an existing Location.

func (*MemoryStore) DeleteRule

func (s *MemoryStore) DeleteRule(ctx context.Context, id int64) error

DeleteRule deletes an existing Rule.

func (*MemoryStore) DeleteSensorRequest

func (s *MemoryStore) DeleteSensorRequest(ctx context.Context, id string) error

DeleteSensorRequest deletes an existing sensor request.

func (*MemoryStore) GetLocation

func (s *MemoryStore) GetLocation(ctx context.Context, name string) (*resources.Location, error)

GetLocation returns the Location with the given name.

func (*MemoryStore) GetSensorRequest

func (s *MemoryStore) GetSensorRequest(ctx context.Context, id string) (*resources.SensorRequest, error)

GetSensorRequest returns the sensor request with the given ID.

func (*MemoryStore) ListLocations

func (s *MemoryStore) ListLocations(ctx context.Context) ([]*resources.Location, error)

ListLocations returns all the locations, sorted by name.

func (*MemoryStore) ListRules

func (s *MemoryStore) ListRules(ctx context.Context, ids []int64) ([]*resources.Rule, error)

ListRules returns Rules from a list of rule IDs. All rules are returned if ids is nil.

func (*MemoryStore) ModifyLocation

func (s *MemoryStore) ModifyLocation(ctx context.Context, l *resources.Location) error

ModifyLocation modifies an existing location with the provided location.

func (*MemoryStore) ModifyRule

func (s *MemoryStore) ModifyRule(ctx context.Context, r *resources.Rule) error

ModifyRule modifies an existing rule with the provided rule.

func (*MemoryStore) ModifySensorRequest

func (s *MemoryStore) ModifySensorRequest(ctx context.Context, r *resources.SensorRequest) error

ModifySensorRequest modifies an existing sensor request with the provided sensor request.

type Store

type Store interface {
	// AddLocation adds a new Location.
	AddLocation(ctx context.Context, l *resources.Location) error
	// ModifyLocation modifies an existing Location.
	ModifyLocation(ctx context.Context, l *resources.Location) error
	// DeleteLocation removes an existing Loction by name.
	DeleteLocation(ctx context.Context, name string) error
	// GetLocation retrieves a Location by name.
	GetLocation(ctx context.Context, name string) (*resources.Location, error)
	// ListLocations lists all stored Locations.
	ListLocations(ctx context.Context) ([]*resources.Location, error)

	// AddRule adds a new Rule.
	AddRule(ctx context.Context, r *resources.Rule) error
	// ModifyRule modifies an existing Rule.
	ModifyRule(ctx context.Context, r *resources.Rule) error
	// DeleteRule removes an existing Rule by ID.
	DeleteRule(ctx context.Context, id int64) error
	// ListRules lists stored Rules by ID.
	ListRules(ctx context.Context, ids []int64) ([]*resources.Rule, error)

	// AddSensorRequest adds a new SensorRequest.
	AddSensorRequest(ctx context.Context, r *resources.SensorRequest) error
	// ModifySensorRequest updates an existing SensorRequest.
	ModifySensorRequest(ctx context.Context, r *resources.SensorRequest) error
	// DeleteSensorRequest removes an existing SensorRequest by request ID.
	DeleteSensorRequest(ctx context.Context, id string) error
	// GetSensorRequest retrieves a SensorRequest by ID.
	GetSensorRequest(ctx context.Context, id string) (*resources.SensorRequest, error)

	// AddSensorMessage adds a new SensorMessage.
	AddSensorMessage(ctx context.Context, r *resources.SensorMessage) error
}

Store represents object storage.

Jump to

Keyboard shortcuts

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