Documentation ¶
Overview ¶
Package models defines data models such as those used to store users and readings.
Index ¶
Constants ¶
const (
// JSONTime is the time format encountered from Spark API
JSONTime = "2006-01-02T15:04:05.000Z"
)
Variables ¶
var ( // ErrorSecretDoesntExist is returned when a SecretStore doesn't // find a requested secret ErrorSecretDoesntExist = errors.New("No secret exists for given criterion") )
var ( // ErrorUserAlreadyExists is returned from a UserStore when a user is // attempted to be stored but already exists in the store. ErrorUserAlreadyExists = errors.New("Entry already exists for user") )
Functions ¶
This section is empty.
Types ¶
type Reading ¶
type Reading struct { UserEmail string `json:"user"` CoreID string `json:"coreid"` Posted time.Time `json:"posted"` Temperature float64 `json:"temperature"` Humidity float64 `json:"humidity"` Moisture float64 `json:"moisture"` Light float64 `json:"light"` Battery float64 `json:"battery"` }
Reading represents a distinct reading of environment attributes sent by a user's Spark 'Core' or other device at specific point in time.
func FilterReadings ¶
FilterReadings takes a slice of readings and a function defining a filter, and returns a subslice of the Readings containing all the matching items.
func ReadingFromJSON ¶
ReadingFromJSON is a convenience method for building a Reading from a request sent by a Particle webhook. Potentially deprecated.
type ReadingStore ¶
type ReadingStore interface { StoreReading(reading Reading) error GetLatestReadings(userEmail string) ([]Reading, error) GetReadings(core string, start, end time.Time) ([]Reading, error) DeleteReadings(core string, start, end time.Time) error }
ReadingStore is an interface for any type that defines methods for storing and accessing readings.
type Secret ¶
type Secret []byte
Secret defines a random value that is used for signing content to verify ownership.
func SecretFromBase64 ¶
SecretFromBase64 is a convenience method for decoding a secret encoded as a base64 string.
type SecretStore ¶
type SecretStore interface { GetSecret(userEmail string) (Secret, error) StoreSecret(userEmail string, secret Secret) error }
SecretStore is an interface for any type that can store and retrieve user secrets.
type User ¶
type User struct { Email string `json:"email"` Name string `json:"name"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Gender string `json:"gender"` Locale string `json:"locale"` }
User is a struct represnting a distinct user of the application and basic data describing that user.