api

package
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2021 License: Apache-2.0 Imports: 25 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NatsSendFileFromHTTP added in v0.0.9

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

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

func NewAppHandler

func NewAppHandler(args ServerArgs) http.Handler

NewAppHandler returns a new application (root) http handler

func NewIndexHandler

func NewIndexHandler(getAsset func(string) []byte) http.Handler

NewIndexHandler returns a new Index handler

func NewNodesHandler added in v0.0.12

func NewNodesHandler(db *genji.Db, v RequestValidator, authToken string,
	nh *NatsHandler) http.Handler

NewNodesHandler returns a new node handler

func NewSendPoints added in v0.0.11

func NewSendPoints(portalURL, deviceID, authToken string, timeout time.Duration, debug bool) func(data.Points) error

NewSendPoints returns a function that can be used to send points to a SimpleIoT portal instance

func NewV1Handler

func NewV1Handler(args ServerArgs) http.Handler

NewV1Handler returns a handle for V1 API

func NewWebsocketHandler

func NewWebsocketHandler(wsTx <-chan []byte, wsRx chan<- []byte, newConn chan<- bool) http.Handler

NewWebsocketHandler returns a new websocket handler. The wsTx channel is used to send data out the websocket, and the newConn channel is used to signal back to the caller that a new client has connected, and the initial data set needs to be sent over.

func Server

func Server(args ServerArgs) error

Server starts a API server instance

func ShiftPath

func ShiftPath(p string) (head, tail string)

ShiftPath is used to extract on segement of URL for processing

Types

type AlwaysValid added in v0.0.5

type AlwaysValid struct{}

AlwaysValid is used to disable authentication

func (AlwaysValid) NewToken added in v0.0.5

func (AlwaysValid) NewToken(id string) (string, error)

NewToken stub

func (AlwaysValid) Valid added in v0.0.5

func (AlwaysValid) Valid(*http.Request) (bool, string)

Valid stub

type App

type App struct {
	PublicHandler http.Handler
	IndexHandler  http.Handler
	V1ApiHandler  http.Handler
}

App is a struct that implements http.Handler interface

func (*App) ServeHTTP

func (h *App) ServeHTTP(res http.ResponseWriter, req *http.Request)

Top level handler for http requests in the coap-server process

type Auth added in v0.0.5

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

Auth handles user authentication requests.

func NewAuthHandler added in v0.0.5

func NewAuthHandler(db *genji.Db, key NewTokener) Auth

NewAuthHandler returns a new authentication handler using the given key.

func (Auth) ServeHTTP added in v0.0.5

func (auth Auth) ServeHTTP(res http.ResponseWriter, req *http.Request)

ServeHTTP serves requests to authenticate.

type Authorizer added in v0.0.5

type Authorizer interface {
	NewToken(id string) (string, error)
	Valid(req *http.Request) (bool, string)
}

Authorizer defines a mechanism needed to authorize stuff

type CoapServer

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

CoapServer manages all the coap requests for this platform

func NewCoapServer

func NewCoapServer(port string) *CoapServer

NewCoapServer creates a new coap server

func (*CoapServer) Start

func (cs *CoapServer) Start() error

Start the coap server

type HTTPLogger added in v0.0.5

type HTTPLogger struct {
	*log.Logger
	// contains filtered or unexported fields
}

HTTPLogger can be used to log http requests

func NewHTTPLogger added in v0.0.5

func NewHTTPLogger(prefix string) *HTTPLogger

NewHTTPLogger returns a http logger

func (*HTTPLogger) Handler added in v0.0.5

func (l *HTTPLogger) Handler(next http.Handler) http.Handler

Handler wraps an HTTP handler and logs the request as necessary.

type IndexHandler

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

IndexHandler is used to serve the index page

func (*IndexHandler) ServeHTTP

func (h *IndexHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Key added in v0.0.5

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

Key provides a key for signing authentication tokens.

func NewKey added in v0.0.5

func NewKey(size int) (key Key, err error)

NewKey returns a new Key of the given size.

func (Key) NewToken added in v0.0.5

func (k Key) NewToken(userID string) (string, error)

NewToken returns a new authentication token signed by the Key.

func (Key) Valid added in v0.0.5

func (k Key) Valid(req *http.Request) (bool, string)

Valid returns whether the given request bears an authorization token signed by the Key.

func (Key) ValidToken added in v0.0.5

func (k Key) ValidToken(str string) (bool, string)

ValidToken returns whether the given string is an authentication token signed by the Key.

type NatsHandler added in v0.0.9

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

NatsHandler implements the SIOT NATS api

func NewNatsHandler added in v0.0.9

func NewNatsHandler(db *genji.Db, authToken, server string) *NatsHandler

NewNatsHandler creates a new NATS client for handling SIOT requests

func (*NatsHandler) Connect added in v0.0.9

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

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

func (*NatsHandler) StartUpdate added in v0.0.9

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

StartUpdate starts an update

type NewTokener added in v0.0.5

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

NewTokener provides a new authentication token.

type NodeCopy added in v0.0.23

type NodeCopy struct {
	ID        string
	NewParent string
}

NodeCopy is a data structured used in the /node/:id/parents api call

type NodeDelete added in v0.0.23

type NodeDelete struct {
	Parent string
}

NodeDelete is a data structure used with /node/:id DELETE call

type NodeMove added in v0.0.15

type NodeMove struct {
	ID        string
	OldParent string
	NewParent string
}

NodeMove is a data structure used in the /node/:id/parents api call

type Nodes added in v0.0.12

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

Nodes handles node requests

func (*Nodes) ServeHTTP added in v0.0.12

func (h *Nodes) ServeHTTP(res http.ResponseWriter, req *http.Request)

Top level handler for http requests in the coap-server process TODO need to add node auth

type Point added in v0.0.11

type Point struct {
	// Type of point (voltage, current, key, etc)
	Type string `json:"type,omitempty" influx:"type,tag"`

	// ID of the device that provided the point
	ID string `json:"id,omitempty" influx:"id,tag"`

	// Average OR
	// Instantaneous analog or digital value of the point.
	// 0 and 1 are used to represent digital values
	Value float64 `json:"value,omitempty" influx:"value"`

	// statistical values that may be calculated
	Min float64 `json:"min,omitempty" influx:"min"`
	Max float64 `json:"max,omitempty" influx:"max"`

	// Time the point was taken
	Time *time.Time `json:"time,omitempty" boltholdKey:"Time" gob:"-" influx:"time"`

	// Duration over which the point was taken
	Duration time.Duration `json:"duration,omitempty" influx:"duration"`
}

Point is a custom value of data.Point with Time set to a pointer. This allows omitempty to work for zero timestamps to avoid bloating JSON packets.

func NewPoint added in v0.0.11

func NewPoint(s data.Point) Point

NewPoint converts a data.Point to Point and rounds floating point values to 3 dec places.

func NewPoints added in v0.0.11

func NewPoints(points []data.Point) []Point

NewPoints converts []data.Sample to []Sample

type RequestValidator added in v0.0.5

type RequestValidator interface {
	Valid(req *http.Request) (bool, string)
}

RequestValidator validates an HTTP request.

type ServerArgs added in v0.0.5

type ServerArgs struct {
	Port       string
	DbInst     *genji.Db
	GetAsset   func(string) []byte
	Filesystem http.FileSystem
	Debug      bool
	JwtAuth    Authorizer
	AuthToken  string
	NH         *NatsHandler
}

ServerArgs can be used to pass arguments to the server subsystem

type V1

type V1 struct {
	GroupsHandler http.Handler
	UsersHandler  http.Handler
	NodesHandler  http.Handler
	AuthHandler   http.Handler
	MsgHandler    http.Handler
}

V1 handles v1 api requests

func (*V1) ServeHTTP

func (h *V1) ServeHTTP(res http.ResponseWriter, req *http.Request)

Top level handler for http requests in the coap-server process

type WebsocketHandler

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

WebsocketHandler handles websocket connections

func (*WebsocketHandler) ServeHTTP

func (h *WebsocketHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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