Documentation
¶
Overview ¶
Package api implments the SIOT http interface.
Index ¶
- func NewAppHandler(args ServerArgs) http.Handler
- func NewIndexHandler(getAsset func(string) []byte) http.Handler
- func NewNodesHandler(db *store.Db, v RequestValidator, authToken string, nc *natsgo.Conn) http.Handler
- func NewSendPoints(portalURL, deviceID, authToken string, timeout time.Duration, debug bool) func(data.Points) error
- func NewV1Handler(args ServerArgs) 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 HTTPLogger
- type IndexHandler
- type Key
- type NewTokener
- type NodeCopy
- type NodeDelete
- type NodeMove
- type Nodes
- type Point
- type RequestValidator
- type ServerArgs
- type V1
- type WebsocketHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewAppHandler ¶
func NewAppHandler(args ServerArgs) http.Handler
NewAppHandler returns a new application (root) http handler
func NewIndexHandler ¶
NewIndexHandler returns a new Index handler
func NewNodesHandler ¶ added in v0.0.12
func NewNodesHandler(db *store.Db, v RequestValidator, authToken string, nc *natsgo.Conn) 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 ¶
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 *store.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 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
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 NewTokener ¶ added in v0.0.5
NewTokener provides a new authentication token.
type NodeCopy ¶ added in v0.0.23
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
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
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"`
// Key of the device that provided the point
Key string `json:"key,omitempty" influx:"key,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"`
// 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.
type RequestValidator ¶ added in v0.0.5
RequestValidator validates an HTTP request.
type ServerArgs ¶ added in v0.0.5
type ServerArgs struct {
Port string
DbInst *store.Db
GetAsset func(string) []byte
Filesystem http.FileSystem
Debug bool
JwtAuth Authorizer
AuthToken string
Nc *nats.Conn
}
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
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)