store

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2022 License: Apache-2.0 Imports: 32 Imported by: 1

Documentation

Overview

Package store implements the SIOT data store and processes messages. Currently data is stored in Genji and Influxdb. Direct DB access is not provided and all write data goes through NATS, thus making it easy to observe any data changes.

Index

Constants

View Source
const (
	StoreTypeMemory Type = "memory"
	StoreTypeBolt        = "bolt"
	StoreTypeBadger      = "badger"
)

define valid store types

Variables

View Source
var DBVersion = 1

DBVersion for this version of siot

Functions

func DumpDb

func DumpDb(gen *Db, out io.Writer) error

DumpDb dumps the entire gen to a file

func ImportDb

func ImportDb(gen *Db, in io.Reader) error

ImportDb imports contents of file into database

func NatsSendFileFromHTTP

func NatsSendFileFromHTTP(nc *nats.Conn, deviceID string, url string, callback func(int)) error

NatsSendFileFromHTTP fetchs a file using http and sends via nats. Callback provides % complete (0-100).

Types

type Db

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

Db represents the store for the application FIXME, Db should be made private at some point and make the dump and import functions part of the store type.

func NewDb

func NewDb(storeType Type, dataDir string) (*Db, error)

NewDb creates a new Db instance for the app

func (*Db) Close

func (gen *Db) Close() error

Close closes the db

type Influx

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

Influx represents and influxdb that we can write points to

func NewInflux

func NewInflux(config *InfluxConfig) *Influx

NewInflux creates an influx helper client

func (*Influx) CheckConfig

func (i *Influx) CheckConfig(config *InfluxConfig)

CheckConfig checks influx config and re-init if necessary

func (*Influx) Close

func (i *Influx) Close()

Close influx client

func (*Influx) WritePoints

func (i *Influx) WritePoints(nodeID, nodeDesc string, points data.Points) error

WritePoints to influxdb

type InfluxConfig

type InfluxConfig struct {
	URL    string
	Token  string
	Org    string
	Bucket string
}

InfluxConfig represents an influxdb config

func NodeToInfluxConfig

func NodeToInfluxConfig(node data.NodeEdge) (*InfluxConfig, error)

NodeToInfluxConfig converts a node to an influx config

type Meta

type Meta struct {
	ID      int    `json:"id"`
	Version int    `json:"version"`
	RootID  string `json:"rootID"`
}

Meta contains metadata about the database

type NewTokener added in v0.0.45

type NewTokener interface {
	NewToken(userID string) (string, error)
}

NewTokener provides a new authentication token.

type Params added in v0.3.0

type Params struct {
	Type      Type
	DataDir   string
	AuthToken string
	Server    string
	Key       NewTokener
	Nc        *nats.Conn
}

Params are used to configure a store

type Store added in v0.3.0

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

Store implements the SIOT NATS api

func NewStore added in v0.3.0

func NewStore(p Params) (*Store, error)

NewStore creates a new NATS client for handling SIOT requests

func (*Store) Start added in v0.3.0

func (st *Store) Start() error

Start connects to NATS server and set up handlers for things we are interested in

func (*Store) StartMetrics added in v0.3.0

func (st *Store) StartMetrics(nodeID string) error

StartMetrics for various handling operations. Metrics are sent to the node ID given FIXME, this can probably move to the node package for device nodes

func (*Store) StartUpdate added in v0.3.0

func (st *Store) StartUpdate(id, url string) error

StartUpdate starts an update

func (*Store) Stop added in v0.3.0

func (st *Store) Stop(err error)

Stop the store

func (*Store) StopMetrics added in v0.3.0

func (st *Store) StopMetrics(_ error)

StopMetrics ...

func (*Store) WaitStart added in v0.3.0

func (st *Store) WaitStart(ctx context.Context) error

WaitStart waits for store to start

type Type

type Type string

Type defines the backing store used for the DB

Jump to

Keyboard shortcuts

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