storage

package
v0.0.0-...-70ad22e Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2014 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDatabase = errors.New("Database Error")
View Source
var ErrUnknownDevice = errors.New("Unknown device")

Functions

This section is empty.

Types

type Device

type Device struct {
	ID                string // device Id
	User              string // userID
	Name              string
	PreviousPositions []Position
	HasPasscode       bool   // is device lockable
	LoggedIn          bool   // is the device logged in
	Secret            string // HAWK secret
	PushUrl           string // SimplePush URL
	Pending           string // pending command
	LastExchange      int32  // last time we did anything
	Accepts           string // commands the device accepts
	AccessToken       string // OAuth Access token
}

Device information

type DeviceList

type DeviceList struct {
	ID   string
	Name string
}

type Position

type Position struct {
	Latitude  float64
	Longitude float64
	Altitude  float64
	Accuracy  float64
	Time      int64
	Cmd       map[string]interface{}
}

Device position

type Storage

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

Storage abstration

func Open

func Open(config *util.MzConfig, logger *util.HekaLogger, metrics *util.Metrics) (store *Storage, err error)

Open the database.

func (*Storage) CheckNonce

func (self *Storage) CheckNonce(nonce string) (bool, error)

Does the user's nonce match?

func (*Storage) Close

func (self *Storage) Close()

func (*Storage) DeleteDevice

func (self *Storage) DeleteDevice(devId string) (err error)

func (*Storage) GcDatabase

func (self *Storage) GcDatabase(devId, userId string) (err error)

Remove old postion information for devices. This previously removed "expired" location records. We currently only retain the latest record for a user.

func (*Storage) GetDeviceInfo

func (self *Storage) GetDeviceInfo(devId string) (devInfo *Device, err error)

Return known info about a device.

func (*Storage) GetDevicesForUser

func (self *Storage) GetDevicesForUser(userId string) (devices []DeviceList, err error)

Get all known devices for this user.

func (*Storage) GetNonce

func (self *Storage) GetNonce() (string, error)

Generate a nonce for OAuth checks

func (*Storage) GetPending

func (self *Storage) GetPending(devId string) (cmd string, err error)

Get pending commands.

func (*Storage) GetPositions

func (self *Storage) GetPositions(devId string) (positions []Position, err error)

func (*Storage) GetUserFromDevice

func (self *Storage) GetUserFromDevice(deviceId string) (userId, name string, err error)

func (*Storage) Init

func (self *Storage) Init() (err error)

Create the tables, indexes and other needed items.

func (*Storage) PurgePosition

func (self *Storage) PurgePosition(devId string) (err error)

remove all tracking information for devId.

func (*Storage) RegisterDevice

func (self *Storage) RegisterDevice(userid string, dev Device) (devId string, err error)

Register a new device to a given userID.

func (*Storage) SetAccessToken

func (self *Storage) SetAccessToken(devId, token string) (err error)

func (*Storage) SetDeviceLocation

func (self *Storage) SetDeviceLocation(devId string, position Position) (err error)

Add the location information to the known set for a device.

func (*Storage) SetDeviceLock

func (self *Storage) SetDeviceLock(devId string, state bool) (err error)

Shorthand function to set the lock state for a device.

func (*Storage) StoreCommand

func (self *Storage) StoreCommand(devId, command, cType string) (err error)

Store a command into the list of pending commands for a device.

func (*Storage) Touch

func (self *Storage) Touch(devId string) (err error)

type Unstructured

type Unstructured map[string]interface{}

Generic structure useful for JSON

Jump to

Keyboard shortcuts

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