Documentation
¶
Index ¶
- func NatsSendFileFromHTTP(nc *n.Conn, deviceID string, url string, callback func(int)) error
- func NewAppHandler(args ServerArgs) http.Handler
- func NewDevicesHandler(db *db.Db, v RequestValidator, nh *NatsHandler) http.Handler
- func NewGetCmd(portalURL, deviceID string, timeout time.Duration, debug bool) func() (data.DeviceCmd, error)
- func NewIndexHandler(getAsset func(string) []byte) http.Handler
- func NewSendSamples(portalURL, deviceID string, timeout time.Duration, debug bool) func([]data.Sample) error
- func NewSetVersion(portalURL, deviceID string, timeout time.Duration, debug bool) func(ver data.DeviceVersion) error
- func NewV1Handler(db *db.Db, auth Authorizer, nh *NatsHandler) http.Handler
- func NewWebsocketHandler(wsTx <-chan []byte, wsRx chan<- []byte, newConn chan<- bool) http.Handler
- func Server(args ServerArgs) error
- func ShiftPath(p string) (head, tail string)
- type AlwaysValid
- type App
- type Auth
- type Authorizer
- type CoapServer
- type Devices
- type Groups
- type HTTPLogger
- type IndexHandler
- type Key
- type NatsHandler
- type NewTokener
- type RequestValidator
- type Sample
- type ServerArgs
- type Users
- type V1
- type WebsocketHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NatsSendFileFromHTTP ¶ added in v0.0.9
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 NewDevicesHandler ¶
func NewDevicesHandler(db *db.Db, v RequestValidator, nh *NatsHandler) http.Handler
NewDevicesHandler returns a new device handler
func NewGetCmd ¶
func NewGetCmd(portalURL, deviceID string, timeout time.Duration, debug bool) func() (data.DeviceCmd, error)
NewGetCmd returns a function that can be used to get device commands from the portal.
func NewIndexHandler ¶
NewIndexHandler returns a new Index handler
func NewSendSamples ¶
func NewSendSamples(portalURL, deviceID string, timeout time.Duration, debug bool) func([]data.Sample) error
NewSendSamples returns a function that can be used to send samples to a SimpleIoT portal instance
func NewSetVersion ¶
func NewSetVersion(portalURL, deviceID string, timeout time.Duration, debug bool) func(ver data.DeviceVersion) error
NewSetVersion sets the device version in the portal
func NewV1Handler ¶
func NewV1Handler(db *db.Db, auth Authorizer, nh *NatsHandler) http.Handler
NewV1Handler returns a handle for V1 API
func NewWebsocketHandler ¶
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.
Types ¶
type AlwaysValid ¶ added in v0.0.5
type AlwaysValid struct{}
AlwaysValid is used to disable authentication
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 *db.Db, key NewTokener) Auth
NewAuthHandler returns a new authentication handler using the given key.
type Authorizer ¶ added in v0.0.5
type Authorizer interface {
NewToken(id uuid.UUID) (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
type Devices ¶
type Devices struct {
// contains filtered or unexported fields
}
Devices handles device requests
func (*Devices) ServeHTTP ¶
func (h *Devices) ServeHTTP(res http.ResponseWriter, req *http.Request)
Top level handler for http requests in the coap-server process TODO need to add device auth
func (*Devices) ServeHTTPDevice ¶ added in v0.0.5
ServeHTTPDevice is used to process requests from device, currently no auth and following URIs: - POST samples - GET cmd - POST version we have already checked for req type, so we can skip that check here
type Groups ¶ added in v0.0.5
type Groups struct {
// contains filtered or unexported fields
}
Groups handles group requests.
func NewGroupsHandler ¶ added in v0.0.5
func NewGroupsHandler(db *db.Db, v RequestValidator) Groups
NewGroupsHandler returns a new handler for group requests.
type HTTPLogger ¶ added in v0.0.5
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
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 (Key) NewToken ¶ added in v0.0.5
NewToken returns a new authentication token signed by the Key.
type NatsHandler ¶ added in v0.0.9
NatsHandler implements the SIOT NATS api
func NewNatsHandler ¶ added in v0.0.9
func NewNatsHandler(db *db.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() 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
NewTokener provides a new authentication token.
type RequestValidator ¶ added in v0.0.5
RequestValidator validates an HTTP request.
type Sample ¶ added in v0.0.5
type Sample struct {
// Type of sample (voltage, current, key, etc)
Type string `json:"type,omitempty" influx:"type,tag"`
// ID of the device that provided the sample
ID string `json:"id,omitempty" influx:"id,tag"`
// Average OR
// Instantaneous analog or digital value of the sample.
// 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 sample was taken
Time *time.Time `json:"time,omitempty" boltholdKey:"Time" gob:"-" influx:"time"`
// Duration over which the sample was taken
Duration time.Duration `json:"duration,omitempty" influx:"duration"`
// Tags are additional attributes used to describe the sample
// You might add things like friendly name, etc.
Tags map[string]string `json:"tags,omitempty" influx:"-"`
// Attributes are additional numerical values
Attributes map[string]float64 `json:"attributes,omitempty" influx:"-"`
}
Sample is a custom value of data.Sample with Time set to a pointer. This allows omitempty to work for zero timestamps to avoid bloating JSON packets.
func NewSample ¶ added in v0.0.5
NewSample converts a data.Sample to Sample and rounds floating point values to 3 dec places.
func NewSamples ¶ added in v0.0.5
NewSamples converts []data.Sample to []Sample
type ServerArgs ¶ added in v0.0.5
type ServerArgs struct {
Port string
DbInst *db.Db
GetAsset func(string) []byte
Filesystem http.FileSystem
Debug bool
Auth Authorizer
NH *NatsHandler
}
ServerArgs can be used to pass arguments to the server subsystem
type Users ¶ added in v0.0.5
type Users struct {
// contains filtered or unexported fields
}
Users handles user requests.
func NewUsersHandler ¶ added in v0.0.5
func NewUsersHandler(db *db.Db, v RequestValidator) Users
NewUsersHandler returns a new handler for user requests.
type V1 ¶
type V1 struct {
GroupsHandler http.Handler
UsersHandler http.Handler
DevicesHandler http.Handler
AuthHandler http.Handler
}
V1 handles v1 api requests
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)