models

package
v0.0.0-...-721f978 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2017 License: MIT Imports: 8 Imported by: 9

Documentation

Overview

Package models defines data models such as those used to store users and readings.

Index

Constants

View Source
const (

	// JSONTime is the time format encountered from Spark API
	JSONTime = "2006-01-02T15:04:05.000Z"
)

Variables

View Source
var (

	// ErrorSecretDoesntExist is returned when a SecretStore doesn't
	// find a requested secret
	ErrorSecretDoesntExist = errors.New("No secret exists for given criterion")
)
View Source
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

func FilterReadings(input []Reading, filter func(Reading) bool) (output []Reading)

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

func ReadingFromJSON(userEmail, coreID string, posted time.Time, JSONStr string) (Reading, error)

ReadingFromJSON is a convenience method for building a Reading from a request sent by a Particle webhook. Potentially deprecated.

func (Reading) Compare

func (r Reading) Compare(b Reading) bool

Compare checks if two readings are the same by checking equality of string fields and that float values are within acceptible margins of each other (because float comparisons tricky).

func (Reading) DataJSON

func (r Reading) DataJSON() string

DataJSON formats just the environmental attributes of the readings into a JSON string. This is primarily used to mock the JSON sent in a Particle webhook for testing.

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 NewSecret

func NewSecret() (Secret, error)

NewSecret creates a new 32 byte (256 bit) secret using crypto/rand

func SecretFromBase64

func SecretFromBase64(base64String string) (Secret, error)

SecretFromBase64 is a convenience method for decoding a secret encoded as a base64 string.

func (Secret) Encode

func (s Secret) Encode() string

Encode returns the secret encoded as a base64 string

func (Secret) Sign

func (s Secret) Sign(input string) string

Sign returns a base64 encoded signature of the input string using the secret and HMAC 256 scheme.

func (Secret) Verify

func (s Secret) Verify(input, signature string) bool

Verify takes the input unsigned string and signature and validates the signature was generated using this secret

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.

type UserStore

type UserStore interface {
	GetUser(email string) (User, error)
	StoreUser(User) error
}

UserStore is an interface represeting types that can store and retrieve user descriptions

Jump to

Keyboard shortcuts

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