Documentation ¶
Index ¶
- func BaseHandle(h interface{}, w http.ResponseWriter, r *http.Request)
- func Timestamp() string
- type Action
- func (action *Action) AsActionDescription() []byte
- func (action *Action) Finish() *Action
- func (action *Action) Href() string
- func (action *Action) ID() string
- func (action *Action) Input() *json.RawMessage
- func (action *Action) Name() string
- func (action *Action) SetHrefPrefix(prefix string)
- func (action *Action) SetInput(input *json.RawMessage)
- func (action *Action) Start() *Action
- func (action *Action) Status() string
- func (action *Action) Thing() *Thing
- func (action *Action) TimeCompleted() string
- func (action *Action) TimeRequested() string
- type ActionHandle
- type ActionIDHandle
- type Actioner
- type ActionsHandle
- type AvailableAction
- type AvailableEvent
- type DeleteInterface
- type Event
- type EventHandle
- type EventObject
- type EventsHandle
- type GetInterface
- type Link
- type MultipleThings
- type PostInterface
- type PropertiesHandle
- type Property
- func (property *Property) AsPropertyDescription() []byte
- func (property *Property) Href() string
- func (property *Property) Metadata() json.RawMessage
- func (property *Property) Name() string
- func (property *Property) SetHrefPrefix(prefix string)
- func (property *Property) SetValue(value *Value) error
- func (property *Property) Thing() *Thing
- func (property *Property) ValidateValue(value interface{}) error
- func (property *Property) Value() *Value
- type PropertyHandle
- type PropertyObject
- type PutInterface
- type SingleThing
- type Thing
- func (thing *Thing) Action(actionName, actionID string) (action *Action)
- func (thing *Thing) ActionDescriptions(actionName string) (descriptions []json.RawMessage)
- func (thing *Thing) ActionNotify(action *Action) error
- func (thing *Thing) AddAvailableAction(name string, metadata json.RawMessage, action Actioner)
- func (thing *Thing) AddAvailableEvent(name string, metadata json.RawMessage)
- func (thing *Thing) AddEvent(event *Event)
- func (thing *Thing) AddEventSubscriber()
- func (thing *Thing) AddProperty(property *Property)
- func (thing *Thing) AddSubscriber(wsID string, ws *websocket.Conn)
- func (thing *Thing) AsThingDescription() []byte
- func (thing *Thing) Context() string
- func (thing *Thing) Description() string
- func (thing *Thing) EventDescriptions(eventName string) []byte
- func (thing *Thing) EventNotify(event *Event) error
- func (thing *Thing) HasProperty(propertyName string) bool
- func (thing *Thing) Href() string
- func (thing *Thing) ID() string
- func (thing *Thing) PerformAction(actionName string, input *json.RawMessage) (*Action, error)
- func (thing *Thing) Properties() map[string]interface{}
- func (thing *Thing) Property(propertyName string) *Value
- func (thing *Thing) PropertyDescriptions() string
- func (thing *Thing) PropertyNotify(property Property) error
- func (thing *Thing) RemoveAction(actionName, actionID string) bool
- func (thing *Thing) RemoveEventSubscriber(name string, ws *websocket.Conn) error
- func (thing *Thing) RemoveProperty(property Property)
- func (thing *Thing) RemoveSubscriber(name string, ws *websocket.Conn)
- func (thing *Thing) SetHrefPrefix(prefix string)
- func (thing *Thing) SetProperty(propertyName string, value *Value) error
- func (thing *Thing) SetUIHref(href string)
- func (thing *Thing) Title() string
- func (thing *Thing) Type() []string
- func (thing *Thing) UIHref() string
- type ThingHandle
- type ThingMember
- type ThingServer
- type ThingsHandle
- type ThingsType
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BaseHandle ¶
func BaseHandle(h interface{}, w http.ResponseWriter, r *http.Request)
BaseHandle Base handler that is initialized with a list of things. func BaseHandle(h BaseHandler, w http.ResponseWriter, r *http.Request) {
Types ¶
type Action ¶
type Action struct { // Override this with the code necessary to perform the action. PerformAction func() *Action // Override this with the code necessary to cancel the action. Cancel func() // contains filtered or unexported fields }
Action An Action represents an individual action on a thing.
func NewAction ¶
func NewAction(id string, thing *Thing, name string, input *json.RawMessage, PerformAction func() *Action, Cancel func()) *Action
NewAction Initialize the object. @param id ID of this action @param thing Thing this action belongs to @param name Name of the action @param input Any action inputs
func (*Action) AsActionDescription ¶
AsActionDescription Get the action description. @return Description of the action as a JSONObject.
func (*Action) Input ¶
func (action *Action) Input() *json.RawMessage
Input Get the inputs for this action. @returns {Object} The inputs.
func (*Action) SetHrefPrefix ¶
SetHrefPrefix Set the prefix of any hrefs associated with this action. @param prefix The prefix
func (*Action) SetInput ¶
func (action *Action) SetInput(input *json.RawMessage)
SetInput Set any input to this action. @param input The input
func (*Action) Status ¶
Status Get this action's status. Get this action's status. @returns {String} The status.
func (*Action) Thing ¶
Thing Get the thing associated with this action. @returns {Object} The thing.
func (*Action) TimeCompleted ¶
TimeCompleted Get the time the action was completed. @returns {String} The time.
func (*Action) TimeRequested ¶
TimeRequested Get the time the action was requested. @returns {String} The time.
type ActionHandle ¶
type ActionHandle struct { *ActionsHandle ActionName string }
ActionHandle Handle a request to /actions/<action_name>.
func (*ActionHandle) Get ¶
func (h *ActionHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a GET request.
@param {Object} r The request object @param {Object} w The response object
func (*ActionHandle) Handle ¶
func (h *ActionHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /actions/<action_name>.
func (*ActionHandle) Post ¶
func (h *ActionHandle) Post(w http.ResponseWriter, r *http.Request)
Post Handle a Post request.
@param {Object} r The request object @param {Object} w The response object
type ActionIDHandle ¶
type ActionIDHandle struct { *ActionHandle *Action }
ActionIDHandle Handle a request to /actions/<action_name>/<action_id>.
func (*ActionIDHandle) Delete ¶
func (h *ActionIDHandle) Delete(w http.ResponseWriter, r *http.Request)
Delete Handle a Delete request.
@param {Object} r The request object @param {Object} w The response object
func (*ActionIDHandle) Get ¶
func (h *ActionIDHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a GET request.
@param {Object} r The request object @param {Object} w The response object
func (*ActionIDHandle) Handle ¶
func (h *ActionIDHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /actions/<action_name>/<action_id>.
type Actioner ¶
type Actioner interface { // Custom Action need create a Generator to generate a action. // The application will invoke the Action created by the Generator method. // This is very similar to simply constructor. // See thing.PerformAction()*Action Generator(thing *Thing) *Action // Override this with the code necessary to perform the action. PerformAction() *Action // Override this with the code necessary to cancel the action. Cancel() Start() *Action Finish() *Action AsActionDescription() []byte SetHrefPrefix(prefix string) ID() string Name() string Href() string Status() string Thing() *Thing TimeRequested() string TimeCompleted() string Input() *json.RawMessage SetInput(input *json.RawMessage) }
Actioner Customize the methods that the action must implement.
type ActionsHandle ¶
type ActionsHandle struct {
*ThingHandle
}
ActionsHandle Handle a request to /actions.
func (*ActionsHandle) Get ¶
func (h *ActionsHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a GET request.
@param {Object} r The request object @param {Object} w The response object
func (*ActionsHandle) Handle ¶
func (h *ActionsHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /actions.
func (*ActionsHandle) Post ¶
func (h *ActionsHandle) Post(w http.ResponseWriter, r *http.Request)
Post Handle a POST request.
@param {Object} req The request object @param {Object} res The response object
type AvailableAction ¶
type AvailableAction struct {
// contains filtered or unexported fields
}
AvailableAction Class to describe an action available to be taken.
func NewAvailableAction ¶
func NewAvailableAction(metadata json.RawMessage, cls Actioner) *AvailableAction
NewAvailableAction Initialize the object.
@param metadata The action metadata @param action Instance for the action
func (*AvailableAction) Action ¶
func (ac *AvailableAction) Action() *Action
Action Get the class to instantiate for the action.
@return The class.
func (*AvailableAction) Metadata ¶
func (ac *AvailableAction) Metadata() []byte
Metadata Get the action metadata.
@return The metadata.
func (*AvailableAction) ValidateActionInput ¶
func (ac *AvailableAction) ValidateActionInput(actionInput interface{}) bool
ValidateActionInput Validate the input for a new action.
@param actionInput The input to validate @return Boolean indicating validation success.
type AvailableEvent ¶
type AvailableEvent struct {
// contains filtered or unexported fields
}
AvailableEvent Class to describe an event available for subscription.
func NewAvailableEvent ¶
func NewAvailableEvent(metadata json.RawMessage) *AvailableEvent
NewAvailableEvent Initialize the object.
@param metadata The event metadata
func (*AvailableEvent) Metadata ¶
func (ae *AvailableEvent) Metadata() json.RawMessage
Metadata Get the event metadata.
@return The metadata.
type DeleteInterface ¶
type DeleteInterface interface {
Delete(w http.ResponseWriter, r *http.Request)
}
DeleteInterface Implementation of http Delete menthod.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event An Event represents an individual event from a thing.
func NewEvent ¶
func NewEvent(thing *Thing, name string, data json.RawMessage) *Event
NewEvent Initialize the object. @param thing Thing this event belongs to @param name Name of the event @param data Data associated with the event
func (*Event) AsEventDescription ¶
AsEventDescription Get the event description. @return Description of the event as a JSONObject.
func (*Event) Data ¶
func (event *Event) Data() json.RawMessage
Data Get the event's data. @returns {*} The data.
type EventHandle ¶
type EventHandle struct { *EventsHandle // contains filtered or unexported fields }
EventHandle handle a request to /events.
func (*EventHandle) Get ¶
func (h *EventHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a GET request.
@param {Object} r The request object @param {Object} w The response object
func (*EventHandle) Handle ¶
func (h *EventHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /events.
type EventObject ¶
type EventObject struct { AtType string `json:"@type,omitempty"` Title string `json:"title,omitempty"` ObjectType string `json:"type,omitempty"` Description string `json:"description,omitempty"` Unit string `json:"unit,omitempty"` Links []Link `json:"links,omitempty"` }
EventObject An event object describes a kind of event which may be emitted by a device. See https://iot.mozilla.org/wot/#event-object
type EventsHandle ¶
type EventsHandle struct {
*ThingHandle
}
EventsHandle a request to /events.
func (*EventsHandle) Get ¶
func (h *EventsHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a GET request.
@param {Object} r The request object @param {Object} w The response object
func (*EventsHandle) Handle ¶
func (h *EventsHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /events.
type GetInterface ¶
type GetInterface interface {
Get(w http.ResponseWriter, r *http.Request)
}
GetInterface Implementation of http Get menthod.
type Link ¶
type Link struct { Href string `json:"href,omitempty"` Rel string `json:"rel,omitempty"` MediaType string `json:"mediaType,omitempty"` }
Link base link struct
type MultipleThings ¶
type MultipleThings struct {
// contains filtered or unexported fields
}
MultipleThings A container for multiple things.
func NewMultipleThings ¶
func NewMultipleThings(things []*Thing, name string) *MultipleThings
NewMultipleThings Initialize the container.
@param {Object} things The things to store @param {String} name The mDNS server name
func (*MultipleThings) Name ¶
func (mt *MultipleThings) Name() string
Name Get the mDNS server name.
func (*MultipleThings) Thing ¶
func (mt *MultipleThings) Thing(idx int) *Thing
Thing Get the thing at the given index.
@param {Number|String} idx The index
func (*MultipleThings) Things ¶
func (mt *MultipleThings) Things() []*Thing
Things Get the list of things.
type PostInterface ¶
type PostInterface interface {
Post(w http.ResponseWriter, r *http.Request)
}
PostInterface Implementation of http Post menthod.
type PropertiesHandle ¶
type PropertiesHandle struct {
*ThingHandle
}
PropertiesHandle Handle a request to /properties.
func (*PropertiesHandle) Get ¶
func (h *PropertiesHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a Get request.
@param {Object} r The request object @param {Object} w The response object
func (*PropertiesHandle) Handle ¶
func (h *PropertiesHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle Handle a request to /properties.
type Property ¶
type Property struct {
// contains filtered or unexported fields
}
Property Initialize the object.
@param thing Thing this property belongs to @param name Name of the property @param value Value object to hold the property value @param metadata Property metadata, i.e. type, description, unit, etc., as
a Map
func NewProperty ¶
NewProperty Initialize the object.
@param {Object} thing Thing this property belongs to @param {String} name Name of the property @param {Value} value Value object to hold the property value @param {Object} metadata Property metadata, i.e. type, description, unit,
etc., as an object.
func (*Property) AsPropertyDescription ¶
AsPropertyDescription Get the property description.
@returns {Object} Description of the property as an object.
func (*Property) Metadata ¶
func (property *Property) Metadata() json.RawMessage
Metadata Get the metadata associated with this property
@returns {Object} The metadata
func (*Property) SetHrefPrefix ¶
SetHrefPrefix Set the prefix of any hrefs associated with this property.
@param {String} prefix The prefix
func (*Property) SetValue ¶
SetValue Set the current value of the property.
@param {*} value The value to set
func (*Property) Thing ¶
Thing Get the thing associated with this property.
@returns {Object} The thing.
func (*Property) ValidateValue ¶
ValidateValue Validate new property value before setting it.
@param {*} value - New value
type PropertyHandle ¶
type PropertyHandle struct { *PropertiesHandle *Property }
PropertyHandle a request to /properties/<property>.
func (*PropertyHandle) Get ¶
func (h *PropertyHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a GET request.
@param {Object} r The request object @param {Object} w The response object
func (*PropertyHandle) Handle ¶
func (h *PropertyHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /properties/<property>.
func (*PropertyHandle) Put ¶
func (h *PropertyHandle) Put(w http.ResponseWriter, r *http.Request)
Put Handle a PUT request.
@param {Object} r The request object @param {Object} w The response object
type PropertyObject ¶
type PropertyObject struct { AtType string `json:"@type,omitempty"` Title string `json:"title,omitempty"` Type string `json:"type,omitempty"` Description string `json:"description,omitempty"` Unit string `json:"unit,omitempty"` ReadOnly bool `json:"readOnly,omitempty"` Minimum json.Number `json:"minimum,omitempty"` Maximum json.Number `json:"maximum,omitempty"` Links []Link `json:"links,omitempty"` }
PropertyObject A property object describes an attribute of a Thing and is indexed by a property id. See https://iot.mozilla.org/wot/#property-object
type PutInterface ¶
type PutInterface interface {
Put(w http.ResponseWriter, r *http.Request)
}
PutInterface Implementation of http Put menthod.
type SingleThing ¶
type SingleThing struct {
// contains filtered or unexported fields
}
SingleThing A container for a single thing.
func NewSingleThing ¶
func NewSingleThing(thing *Thing) *SingleThing
NewSingleThing Initialize the container.
@param {Object} thing The thing to store
func (*SingleThing) Thing ¶
func (st *SingleThing) Thing(idx int) *Thing
Thing Get the thing at the given index.
func (*SingleThing) Things ¶
func (st *SingleThing) Things() []*Thing
Things Get the list of things.
type Thing ¶
type Thing struct {
// contains filtered or unexported fields
}
Thing A Web Thing struct.
func (*Thing) Action ¶
Action Get an action.
@param actionName Name of the action @param actionId ID of the action @return The requested action if found, else null.
func (*Thing) ActionDescriptions ¶
func (thing *Thing) ActionDescriptions(actionName string) (descriptions []json.RawMessage)
ActionDescriptions Get the thing's actions as an array.
@param {String?} actionName Optional action name to get descriptions for @returns {Object} Action descriptions.
func (*Thing) ActionNotify ¶
ActionNotify Notify all subscribers of an action status change.
@param action The action whose status changed
func (*Thing) AddAvailableAction ¶
func (thing *Thing) AddAvailableAction(name string, metadata json.RawMessage, action Actioner)
AddAvailableAction Add an available action.
@param name Name of the action @param metadata Action metadata, i.e. type, description, etc., as a
JSONObject
@param action Instantiate for this action
func (*Thing) AddAvailableEvent ¶
func (thing *Thing) AddAvailableEvent(name string, metadata json.RawMessage)
AddAvailableEvent Add an available event.
@param name Name of the event @param metadata Event metadata, i.e. type, description, etc., as a
JSONObject
func (*Thing) AddEvent ¶
AddEvent Add a new event and notify subscribers.
@param event The event that occurred.
func (*Thing) AddEventSubscriber ¶
func (thing *Thing) AddEventSubscriber()
AddEventSubscriber Add a new websocket subscriber to an event.
@param name Name of the event @param ws The websocket
func (*Thing) AddProperty ¶
AddProperty Add a property to this thing.
@param property Property to add.
func (*Thing) AsThingDescription ¶
AsThingDescription retrun []byte data of thing struct. Return the thing state as a Thing Description. @returns {Object} Current thing state
func (*Thing) Context ¶
Context Get the type context of the thing.
@returns {String} The contexthing.
func (*Thing) Description ¶
Description Get the description of the thing.
@returns {String} The description.
func (*Thing) EventDescriptions ¶
EventDescriptions Get the thing's events as an array.
@param {String?} eventName Optional event name to get descriptions for
@returns {Object} Event descriptions.
func (*Thing) EventNotify ¶
EventNotify Notify all subscribers of an event.
@param event The event that occurred
func (*Thing) HasProperty ¶
Determine whether or not this thing has a given property.
@param propertyName The property to look for @return Indication of property presence.
func (*Thing) PerformAction ¶
PerformAction Perform an action on the thing.
@param actionName Name of the action @param input Any action inputs @return The action that was created.
func (*Thing) Properties ¶
Properties et a mapping of all properties and their values.
@return JSON object of propertyName -> value.
func (*Thing) Property ¶
Property Get a property's value.
@param propertyName Name of the property to get the value of @param <T> Type of the property value @return Current property value if found, else null.
func (*Thing) PropertyDescriptions ¶
PropertyDescriptions Get the thing's properties as an object.
@returns {Object} Properties, i.e. name -> description
func (*Thing) PropertyNotify ¶
PropertyNotify Notify all subscribers of a property change.
@param property The property that changed
func (*Thing) RemoveAction ¶
RemoveAction Remove an existing action.
@param actionName name of the action @param actionId ID of the action @return Boolean indicating the presence of the action.
func (*Thing) RemoveEventSubscriber ¶
RemoveEventSubscriber Remove a websocket subscriber from an event.
@param name Name of the event @param ws The websocket
func (*Thing) RemoveProperty ¶
RemoveProperty Remove a property from this thing.
@param property Property to remove.
func (*Thing) RemoveSubscriber ¶
RemoveSubscriber Remove a websocket subscriber.
@param ws The websocket
func (*Thing) SetHrefPrefix ¶
SetHrefPrefix Set the prefix of any hrefs associated with this thing.
@param {String} prefix The prefix
func (*Thing) SetProperty ¶
SetProperty Set a property value.
@param propertyName Name of the property to set @param value Value to set @param <T> Type of the property value @throws PropertyError If value could not be set.
func (*Thing) SetUIHref ¶
SetUIHref Set the href of this thing's custom UI.
@param {String} href The href
type ThingHandle ¶
type ThingHandle struct {
*Thing
}
ThingHandle Handle a request to thing.
func (*ThingHandle) Get ¶
func (h *ThingHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a Get request.
@param {Object} r The request object @param {Object} w The response object
func (*ThingHandle) Handle ¶
func (h *ThingHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle a request to /thing.
type ThingMember ¶
type ThingMember struct { ID string `json:"id"` Context string `json:"@context"` AtType []string `json:"@type"` Title string `json:"title"` Description string `json:"description,omitempty"` Properties json.RawMessage `json:"properties,omitempty"` Actions map[string]json.RawMessage `json:"actions,omitempty"` Events map[string]json.RawMessage `json:"events,omitempty"` Links []Link `json:"links"` }
ThingMember thingmember
func NewThingMember ¶
func NewThingMember(thing *Thing) *ThingMember
type ThingServer ¶
ThingServer Web Thing Server.
func NewWebThingServer ¶
func NewWebThingServer(thingType ThingsType, httpServer *http.Server, basePath string) *ThingServer
NewWebThingServer Initialize the WebThingServer.
@param thingType List of Things managed by this server @param basePath Base URL path to use, rather than '/'
func (*ThingServer) Start ¶
func (server *ThingServer) Start() error
Start Start listening for incoming connections.
@return Error on failure to listen on port
type ThingsHandle ¶
type ThingsHandle struct { Things []*Thing // contains filtered or unexported fields }
ThingsHandle things struct.
func (*ThingsHandle) Get ¶
func (h *ThingsHandle) Get(w http.ResponseWriter, r *http.Request)
Get Handle a Get request.
@param {Object} r The request object @param {Object} w The response object
func (*ThingsHandle) Handle ¶
func (h *ThingsHandle) Handle(w http.ResponseWriter, r *http.Request)
Handle handle request.
type ThingsType ¶
type ThingsType interface { // Thing Get the thing at the given index. // // @param idx Index of thing. // @return The thing, or null. Thing(idx int) *Thing // Things Get the list of things. // // @return The list of things. Things() []*Thing // Name Get the mDNS server name. // // @return The server name. Name() string }
ThingsType Container of Things Type
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
Value A property value.
This is used for communicating between the Thing representation and the actual physical thing implementation.
Notifies all observers when the underlying value changes through an external update (command to turn the light off) or if the underlying sensor reports a new value.
func NewValue ¶
func NewValue(initialValue interface{}, valueForwarder ...func(interface{})) Value
NewValue Initialize the object.
@param {*} initialValue The initial value @param {function?} valueForwarder The method that updates the actual value
on the thing
func (*Value) Get ¶
func (v *Value) Get() interface{}
Get Return the last known value from the underlying thing.
@returns the value.
func (*Value) NotifyOfExternalUpdate ¶
func (v *Value) NotifyOfExternalUpdate(value interface{})
NotifyOfExternalUpdate Notify observers of a new value.
@param {*} value New value