Documentation ¶
Index ¶
- func GetJSON(urlStr string, target interface{}) error
- func HandleGetRequest(w http.ResponseWriter, r *http.Request, h *func() interface{})
- func NewBadRequestError(err error) error
- func NewErrorWithStatusCode(err error, status int) error
- func NewRequestInternalServerError(err error) error
- func NewRequestMethodNotAllowed(err error) error
- func NewRequestNotFound(err error) error
- func NewRequestNotImplemented(err error) error
- func PostJSON(urlStr string, data interface{}, expectedStatus int) (*http.Response, error)
- func RandomID(n int) string
- func SendError(w http.ResponseWriter, error error)
- func SendJSONResponse(w http.ResponseWriter, status int, data interface{})
- func URLEncoded(str string) string
- type ConnectorModuleBase
- func (c *ConnectorModuleBase) GetConnectorModuleData() *ConnectorModuleData
- func (c *ConnectorModuleBase) GetDescription() string
- func (c *ConnectorModuleBase) GetEndpoints() []Endpoint
- func (c *ConnectorModuleBase) GetID() string
- func (c *ConnectorModuleBase) GetName() string
- func (c *ConnectorModuleBase) GetSettings(settings interface{}) error
- func (c *ConnectorModuleBase) SendError(err error, fatal bool)
- func (c *ConnectorModuleBase) SendLocation(host, thingID string, location Location)
- func (c *ConnectorModuleBase) SendObservation(host, datastreamID string, observation Observation)
- func (c *ConnectorModuleBase) SetConnectorModuleData(data *ConnectorModuleData)
- func (c *ConnectorModuleBase) SetID(id string)
- type ConnectorModuleData
- type ConnectorModuleStatus
- type Endpoint
- type EndpointError
- type EndpointOperation
- type ErrorContent
- type ErrorMessage
- type ErrorResponse
- type FeatureOfInterest
- type HTTPOperation
- type IConnectorModule
- type Location
- type LocationMessage
- type Observation
- type ObservationMessage
- type PostStatus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetJSON ¶
GetJSON is used to fetch data for a given url and getting parsed into a given interface
func HandleGetRequest ¶
func HandleGetRequest(w http.ResponseWriter, r *http.Request, h *func() interface{})
HandleGetRequest is the default function to handle incoming GET requests
func NewBadRequestError ¶
NewBadRequestError creates an apiError with status code 400.
func NewErrorWithStatusCode ¶
NewErrorWithStatusCode creates a new apiError with a given status code
func NewRequestInternalServerError ¶
NewRequestInternalServerError creates an apiError with status code 500.
func NewRequestMethodNotAllowed ¶
NewRequestMethodNotAllowed creates an apiError with status code 405.
func NewRequestNotFound ¶
NewRequestNotFound creates an apiError with status code 404.
func NewRequestNotImplemented ¶
NewRequestNotImplemented creates an apiError with status code 501.
func RandomID ¶
RandomID gives back a random ID that can be used when no id was defined for a module
func SendError ¶
func SendError(w http.ResponseWriter, error error)
SendError creates an ErrorResponse message and sets it to the user using SendJSONResponse
func SendJSONResponse ¶
func SendJSONResponse(w http.ResponseWriter, status int, data interface{})
SendJSONResponse sends the desired message to the user the message will be marshalled into an indented JSON format
func URLEncoded ¶
URLEncoded encodes a string like Javascript's encodeURIComponent()
Types ¶
type ConnectorModuleBase ¶
type ConnectorModuleBase struct { ID string ModuleName string ModuleDescription string AllowDuplicateResults bool ModuleData *ConnectorModuleData Endpoints []Endpoint LatestObservationResults map[string]map[string]string // contains filtered or unexported fields }
ConnectorModuleBase is the base implementation for a module this can be used to easily create a new module
func (*ConnectorModuleBase) GetConnectorModuleData ¶
func (c *ConnectorModuleBase) GetConnectorModuleData() *ConnectorModuleData
GetConnectorModuleData returns the ModuleData of a module
func (*ConnectorModuleBase) GetDescription ¶
func (c *ConnectorModuleBase) GetDescription() string
GetDescription returns the module description
func (*ConnectorModuleBase) GetEndpoints ¶
func (c *ConnectorModuleBase) GetEndpoints() []Endpoint
GetEndpoints return the configured endpoints for the module
func (*ConnectorModuleBase) GetID ¶
func (c *ConnectorModuleBase) GetID() string
GetID returns the module id
func (*ConnectorModuleBase) GetName ¶
func (c *ConnectorModuleBase) GetName() string
GetName returns the module name
func (*ConnectorModuleBase) GetSettings ¶
func (c *ConnectorModuleBase) GetSettings(settings interface{}) error
GetSettings reads a (JSON) config file for the module and parses it into the given settings interface config files should have the name of the plugin name i.e. netatmo.so should have a config file named netatmo.json
func (*ConnectorModuleBase) SendError ¶
func (c *ConnectorModuleBase) SendError(err error, fatal bool)
SendError sends an error message over the ErrorChannel to the connector
func (*ConnectorModuleBase) SendLocation ¶
func (c *ConnectorModuleBase) SendLocation(host, thingID string, location Location)
SendLocation sends a location message over the LocationChannel to the connector
func (*ConnectorModuleBase) SendObservation ¶
func (c *ConnectorModuleBase) SendObservation(host, datastreamID string, observation Observation)
SendObservation sends an error message over the ObservationChannel to the connector
func (*ConnectorModuleBase) SetConnectorModuleData ¶
func (c *ConnectorModuleBase) SetConnectorModuleData(data *ConnectorModuleData)
SetConnectorModuleData sets the incoming ModuleData
func (*ConnectorModuleBase) SetID ¶
func (c *ConnectorModuleBase) SetID(id string)
SetID returns the module id
type ConnectorModuleData ¶
type ConnectorModuleData struct { ModuleFileName string `json:"fileName"` ModuleFilePath string `json:"filePath"` ConnectorVersion string `json:"-"` Status *ConnectorModuleStatus `json:"status"` ObservationChannel *chan ObservationMessage `json:"-"` LocationChannel *chan LocationMessage `json:"-"` ErrorChannel *chan ErrorMessage `json:"-"` }
ConnectorModuleData will be send to the init function of a ConnectorModule Data in here can be used for initialisation/sending data
func NewConnectorModuleData ¶
func NewConnectorModuleData(version, fileName, filePath string, obsChannel *chan ObservationMessage, locChannel *chan LocationMessage, errorChannel *chan ErrorMessage) *ConnectorModuleData
NewConnectorModuleData creates a new ConnectorModuleData object
func (*ConnectorModuleData) AddError ¶
func (c *ConnectorModuleData) AddError(err error)
AddError adds a new error to the list of errors for the module
type ConnectorModuleStatus ¶
type ConnectorModuleStatus struct { MaxErrors int `json:"-"` Fatal bool `json:"fatal"` Running bool `json:"running"` LastGet string `json:"lastGet"` LastPost string `json:"lastPost"` ObservationsPostedOk int64 `json:"postSuccess"` ObservationsPostedFailed int64 `json:"postFailed"` ErrorCount int `json:"errorCount"` LastErrors []string `json:"lastErrors"` }
ConnectorModuleStatus contains information about the status of a module
type Endpoint ¶
type Endpoint struct { Name string `json:"name"` Operations []EndpointOperation `json:"operations"` }
Endpoint holds the information about an endpoint for a module
func (*Endpoint) GetOperations ¶
func (e *Endpoint) GetOperations() []EndpointOperation
GetOperations returns the operations for an endpoint
type EndpointError ¶
type EndpointError struct {
// contains filtered or unexported fields
}
EndpointError holds information about an error including status codes.
func (EndpointError) Error ¶
func (e EndpointError) Error() string
Error implements the error interface for apiError
func (EndpointError) GetHTTPErrorStatusCode ¶
func (e EndpointError) GetHTTPErrorStatusCode() int
GetHTTPErrorStatusCode returns the status code.
type EndpointOperation ¶
type EndpointOperation struct { OperationType HTTPOperation `json:"operation"` Path string `json:"path"` //relative path to the endpoint for example: /v1.0/myendpoint/ Handler httprouter.Handle `json:"-"` }
EndpointOperation contains the needed information to create an endpoint in the HTTP.Router
type ErrorContent ¶
type ErrorContent struct { StatusText string `json:"status"` StatusCode int `json:"code"` Message string `json:"message"` }
ErrorContent holds information on the error that occurred
type ErrorMessage ¶
ErrorMessage send over ErrorChannel, an ErrorMessage should be send from a module when an error occurs so it can be logged from the connector
type ErrorResponse ¶
type ErrorResponse struct {
Error ErrorContent `json:"error"`
}
ErrorResponse is the default response format for sending errors back
type FeatureOfInterest ¶
type FeatureOfInterest struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` EncodingType string `json:"encodingType,omitempty"` Feature map[string]interface{} `json:"feature,omitempty"` }
FeatureOfInterest in SensorThings represents the phenomena an Observation is detecting. In some cases a FeatureOfInterest can be the Location of the Sensor and therefore of the Observation. A FeatureOfInterest is linked to a single Observation
type HTTPOperation ¶
type HTTPOperation string
HTTPOperation describes the HTTP operation such as GET POST DELETE.
const ( HTTPOperationGet HTTPOperation = "GET" HTTPOperationPost HTTPOperation = "POST" HTTPOperationPatch HTTPOperation = "PATCH" HTTPOperationDelete HTTPOperation = "DELETE" )
HTTPOperation is a "enumeration" of the HTTP operations needed for all endpoints.
type IConnectorModule ¶
type IConnectorModule interface { Setup() error Start(onStartup bool) error Stop() GetID() string GetName() string GetDescription() string GetConnectorModuleData() *ConnectorModuleData GetEndpoints() []Endpoint SetID(string) SetConnectorModuleData(*ConnectorModuleData) }
IConnectorModule defines the functions that need to be implemented by a module
type Location ¶
type Location struct { Name string `json:"name,omitempty"` Description string `json:"description,omitempty"` EncodingType string `json:"encodingType,omitempty"` Location map[string]interface{} `json:"location,omitempty"` }
Location entity locates the Thing or the Things it associated with. A Thing’s Location entity is defined as the last known location of the Thing. A Thing’s Location may be identical to the Thing’s Observations’ FeatureOfInterest. In the context of the IoT, the principle location of interest is usually associated with the location of the Thing, especially for in-situ sensing applications. For example, the location of interest of a wifi-connected thermostat should be the building or the room in which the smart thermostat is located. And the FeatureOfInterest of the Observations made by the thermostat (e.g., room temperature readings) should also be the building or the room. In this case, the content of the smart thermostat’s location should be the same as the content of the temperature readings’ feature of interest.
type LocationMessage ¶
type LocationMessage struct { ModuleID string Host string ThingID string Location Location Status PostStatus }
LocationMessage can be passed from a module to the connector location message channel, this will be used to post a new location for a Thing
type Observation ¶
type Observation struct { PhenomenonTime string `json:"phenomenonTime,omitempty"` Result interface{} `json:"result,omitempty"` ResultTime *string `json:"resultTime,omitempty"` ResultQuality string `json:"resultQuality,omitempty"` ValidTime string `json:"validTime,omitempty"` Parameters map[string]interface{} `json:"parameters,omitempty"` FeatureOfInterest *FeatureOfInterest `json:"featureOfInterest,omitempty"` }
Observation in SensorThings represents a single Sensor reading of an ObservedProperty. A physical device, a Sensor, sends Observations to a specified Datastream. An Observation requires a FeatureOfInterest entity, if none is provided in the request, the Location of the Thing associated with the Datastream, will be assigned to the new Observation as the FeaturOfInterest.
type ObservationMessage ¶
type ObservationMessage struct { ModuleID string Host string DatastreamID string Observation Observation Status PostStatus }
ObservationMessage can be passed from a module to the connector observation message channel, this will be used to post observation data to a Datastream
type PostStatus ¶
PostStatus function definition is used as a callback when posting data to a SensorThings server