store

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

Package store implements database store code -- currently Genji and Influxdb. Also contains NATS handlers to receive data. This allows us to keep the db write functions private and force all write data through NATS, and thus makes 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 *natsgo.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

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 NatsHandler

type NatsHandler struct {
	Nc *natsgo.Conn
	// contains filtered or unexported fields
}

NatsHandler implements the SIOT NATS api

func NewNatsHandler

func NewNatsHandler(db *Db, authToken, server string, key NewTokener) *NatsHandler

NewNatsHandler creates a new NATS client for handling SIOT requests

func (*NatsHandler) Connect

func (nh *NatsHandler) Connect() (*natsgo.Conn, error)

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

func (*NatsHandler) StartMetrics

func (nh *NatsHandler) StartMetrics(nodeID string) error

StartMetrics for various handling operations. Metrics are sent to the node ID given

func (*NatsHandler) StartUpdate

func (nh *NatsHandler) StartUpdate(id, url string) error

StartUpdate starts an update

type NewTokener added in v0.0.45

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

NewTokener provides a new authentication token.

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