Documentation ¶
Index ¶
- Variables
- func ActorItemValues(b Bus, types ...api.Type) map[interface{}]string
- func Config() api.FieldMap
- func ConfigRead(b Bus, key string) (interface{}, error)
- func ConfigRemove(b Bus, key string) error
- func ConfigWrite(b Bus, key string, value interface{}) error
- func ItemAdd(b Bus, item Item) error
- func ItemRemove(b Bus, item Item) error
- func SensorItemValues(b Bus, types ...api.Type) map[interface{}]string
- func SplitBusID(id string) (instance string, key string, action string)
- type APIPlugin
- type ActorItem
- type ActorItemChecker
- type Bus
- type ConfigPlugin
- type Event
- type EventItem
- type EventItemChecker
- type EventService
- type EventTrigger
- type HTTPContext
- type InitService
- type Item
- type ItemValue
- type LoggerItem
- type LoggerItemChecker
- type PathEntry
- type Plugin
- type PluginConfig
- type PluginConfigDef
- type PluginConfigEntryDef
- type PluginConfigEntryDefMap
- type Request
- type RequestHandler
- type RequestService
- type Response
- type Script
- type ScriptDefinition
- type ScriptFunction
- type ScriptModule
- type ScriptModuleDefinition
- type SensorItem
- type SensorItemChecker
- type SensorItemSingle
- type Service
- type ShutdownPlugin
- type ShutdownService
- type SimplePathEntry
- type SimplePathEntryHandler
- type StartService
- type TestBus
- func (t *TestBus) HandleRequest(request Request)
- func (t *TestBus) HandleRequestWait(request Request, timeout time.Duration) Response
- func (t *TestBus) RegisterEventListener(id string, listener chan Event) error
- func (t *TestBus) RegisterService(service Service) error
- func (t *TestBus) Shutdown()
- func (t *TestBus) Start() error
- func (t *TestBus) UnregisterEventListener(id string, listener chan Event)
- type UpdateIntervalService
- type UpdateService
- type ValuesItem
- type WebPlugin
Constants ¶
This section is empty.
Variables ¶
var ActorItemValueType = &itemValueType{"actor"}
ActorItemValueType represents an actor item value
var ItemValueType = &itemValueType{}
ItemValueType represents an item value
var SensorItemValueType = &itemValueType{"sensor"}
SensorItemValueType represents an sensor item value
Functions ¶
func ActorItemValues ¶ added in v0.6.0
ActorItemValues matching the given type or any item value if no type given
func ConfigRead ¶
ConfigRead returns the config value from the given key
func ConfigRemove ¶
ConfigRemove removes the given config key
func ConfigWrite ¶
ConfigWrite writes the given config value
func SensorItemValues ¶ added in v0.6.0
SensorItemValues matching the given type or any item value if no type given
Types ¶
type APIPlugin ¶
type APIPlugin interface { Plugin // APIEndpoints returns list of endpoints provided by plugin APIEndpoints() []PathEntry }
APIPlugin provides API endpoints
type ActorItem ¶
type ActorItem interface { ValuesItem // SetValues of actor SetValues(values map[string]interface{}) error }
ActorItem provides the functionality to write values
func GetActorItem ¶
GetActorItem return the actor item if item is a actor
type ActorItemChecker ¶
type ActorItemChecker interface { // IsActorItem returns true if item is a actor IsActorItem() bool }
ActorItemChecker provides interface to check if actor item
type Bus ¶
type Bus interface { // Start sends start event to all services Start() error // Shutdown bus and stop all services in reverse order of registration Shutdown() // RegisterService to bus instance RegisterService(service Service) error // HandleRequest forwards the request to the assigned service HandleRequest(request Request) // HandleRequestWait handles request and wait for response // // Note: This will overwrite the response channel if set HandleRequestWait(request Request, timeout time.Duration) Response // RegisterEventListener registers a new listener for the given key RegisterEventListener(id string, listener chan Event) error // UnregisterEventListener remove the registered listener UnregisterEventListener(id string, listener chan Event) }
The Bus is the main communication interface between multiple components
type ConfigPlugin ¶
type ConfigPlugin interface { Plugin // Config returns the definition of the Config interface Config() *PluginConfigDef }
ConfigPlugin provides generic configuration
type EventItem ¶
type EventItem interface { Item // Events returns all events that can be emitted Events() map[string]api.SimpleHandler // SetEventTrigger for item event SetEventTrigger(trigger func(action string, data map[string]interface{})) }
EventItem will trigger events
func GetEventItem ¶
GetEventItem return the event item if item is a event
type EventItemChecker ¶
type EventItemChecker interface { // IsEventItem returns true if item is a event IsEventItem() bool }
EventItemChecker provides interface to check if event item
type EventService ¶
type EventService interface { Service // Events returns all events that can be emitted Events() map[string]api.SimpleHandler // SetEventTrigger for service SetEventTrigger(trigger EventTrigger) }
EventService represent an endpoint that emit events
type EventTrigger ¶
EventTrigger will trigger an event and forward to listener
type HTTPContext ¶
type HTTPContext interface { // Request from HTTP client Request() *http.Request // Writer returns HTTP response object Writer() http.ResponseWriter // Next will execute pending handlers (inside current handler) Next() // # # # # # parse request # # # # # // GetHeader returns value from request headers GetHeader(key string) string // Header is a intelligent shortcut for c.Writer.Header().Set(key, value). // It writes a header in the response. // If value == "", this method removes the header `c.Writer.Header().Del(key)` Header(key, value string) // Param returns the value of the URL param. Param(key string) string // BodyValue returns value from body. BodyValue(key string) interface{} // PostForm returns the POST form data PostForm(key string) string // # # # # # request metadata # # # # # // Set store a key value pair for this context Set(key string, value interface{}) // Get returns the value for the given key Get(key string) (value interface{}, exists bool) // MustGet returns the value for the given key or panics if not exist MustGet(key string) interface{} // # # # # # manipulate handling # # # # # // Abort prevents pending handlers from being called Abort() // IsAborted returns true if the current context was aborted. IsAborted() bool // AbortWithStatusJSON calls `Abort()` and then `JSON` internally. AbortWithStatusJSON(code int, jsonObj interface{}) // # # # # # send response # # # # # // JSON serializes the given struct as JSON into the response body. // It also sets the Content-Type as "application/json". JSON(code int, obj interface{}) // XML serializes the given struct as XML into the response body. // It also sets the Content-Type as "application/xml". XML(code int, obj interface{}) // Status sets the HTTP response code. Status(code int) // Redirect redirect to location Redirect(code int, location string) // BusResponse writes a bus response to http context BusResponse(response Response) }
HTTPContext provides an interface for handling of HTTP requests
type InitService ¶
InitService -> a service that handle init event
type Item ¶
type Item interface { // Identifier of item ID() string // User friendly name of item Name() string }
Item that can be handled by the item service
type ItemValue ¶ added in v0.6.0
ItemValue represents a specific value from an item
func NewItemValue ¶ added in v0.6.0
NewItemValue from string
func (ItemValue) MarshalYAML ¶ added in v0.6.0
MarshalYAML converts struct to item value string
type LoggerItem ¶
type LoggerItem interface { Item // LogValues to persistent storage LogValues(id string, values map[string]interface{}) error }
LoggerItem will log values to persistent storage
func GetLoggerItem ¶
func GetLoggerItem(item Item) (LoggerItem, bool)
GetLoggerItem return the logger item if item is a logger
type LoggerItemChecker ¶
type LoggerItemChecker interface { // IsLoggerItem returns true if item is a logger IsLoggerItem() bool }
LoggerItemChecker provides interface to check if logger item
type PathEntry ¶
type PathEntry struct { // Definition of entry (only used for endpoint) Def api.ExtendedHandler // Group of entry (only used for endpoint) Group string // Path to this entry Path string // Method that this entry will handle (only used for endpoint) Method string // FileSystem for handling of static files (can not be used with Handler and SubEntries) FileSystem http.FileSystem // Middleware to handle before endpoint Middleware []func(ctx HTTPContext) // Handler if this is an endpoint Handler func(ctx HTTPContext) // SubEntries under this one SubEntries []PathEntry }
PathEntry defines part of http routing
func APIWrapper ¶
func APIWrapper(b Bus, service RequestService, action string, entry PathEntry) PathEntry
APIWrapper creates a wrapper to forward an API request to the bus
type Plugin ¶
type Plugin interface { // ID of plugin ID() string // Version information of plugin Version() string // Init plugin Init(b Bus) error }
Plugin that provides functionality
type PluginConfig ¶
type PluginConfig struct { // Configuration of current entry Config map[string]interface{} // configuration of sub entries Entries map[string]map[string]map[string]interface{} }
PluginConfig stores current configuration
type PluginConfigDef ¶
type PluginConfigDef struct { // Global plugin configuration Config api.FieldMap `json:"config,omitempty"` // Called to load Config after startup LoadFunc func(config map[string]interface{}) error `json:"-"` // Called if Config was changed ChangeFunc func(config map[string]interface{}) error `json:"-"` // Map of sub entry configuration Entries PluginConfigEntryDefMap `json:"entries,omitempty"` }
PluginConfigDef defines configuration structure of plugin
func (*PluginConfigDef) Load ¶
func (d *PluginConfigDef) Load(data interface{}) (*PluginConfig, error)
Load configuration from raw data
func (*PluginConfigDef) Validate ¶
func (d *PluginConfigDef) Validate() error
Validate if all required functions are provided
type PluginConfigEntryDef ¶
type PluginConfigEntryDef struct { // Config of entry Config api.FieldMap `json:"config,omitempty"` // Order index of entry Order int // Called to load Config entries after startup LoadEntryFunc func(entries map[string]map[string]interface{}) error `json:"-"` // Called to add a new Config entry AddEntryFunc func(key string, config map[string]interface{}) error `json:"-"` // Called to change a Config entry (optional) ChangeEntryFunc func(key string, config map[string]interface{}) error `json:"-"` // Called to remove a Config entry RemoveEntryFunc func(key string) error `json:"-"` }
PluginConfigEntryDef defines configuration structure of sub Config entries
func (*PluginConfigEntryDef) Load ¶
func (d *PluginConfigEntryDef) Load(data interface{}) (map[string]map[string]interface{}, error)
Load configuration from raw data
func (*PluginConfigEntryDef) Validate ¶
func (d *PluginConfigEntryDef) Validate() error
Validate if all required functions are provided
type PluginConfigEntryDefMap ¶
type PluginConfigEntryDefMap map[string]PluginConfigEntryDef
PluginConfigEntryDefMap provides a sortable map of PluginConfigEntryDef
func (PluginConfigEntryDefMap) SortedKeys ¶
func (d PluginConfigEntryDefMap) SortedKeys() []string
SortedKeys returns list with sorted map keys (uses Order if set)
type Request ¶
type Request struct { // Identifier of request handler ID string // Parameters of action Parameters map[string]interface{} // Channel for response ResponseChannel chan Response }
Request that is handled by a service
type RequestHandler ¶
type RequestHandler struct { Def api.SimpleHandler // Function that handles the request Func func(map[string]interface{}) (map[string]interface{}, error) }
RequestHandler will handle a request
type RequestService ¶
type RequestService interface { Service // Handlers returns a map with all supported action and their handle functions Handlers() map[string]RequestHandler }
RequestService represent an endpoint for the bus that handles received requests
type Response ¶
type Response struct { // Original response OrgRequest Request // Error if not successful Error error Data map[string]interface{} }
Response of a handled request
type ScriptDefinition ¶
type ScriptDefinition struct { // modules available in script Modules map[string]ScriptModuleDefinition // function available outside packages GlobalFunctions map[string]ScriptFunction // global const values ConstantValues map[string]interface{} }
ScriptDefinition defines the functionality of a script
type ScriptFunction ¶
type ScriptFunction struct { Def api.Function Func func(script Script, args []interface{}) []interface{} }
ScriptFunction defines a function that can be called from script
type ScriptModule ¶
type ScriptModule interface { Name() string Def() ScriptModuleDefinition }
ScriptModule object
type ScriptModuleDefinition ¶
type ScriptModuleDefinition struct { Description string Functions map[string]ScriptFunction CleanupFunc func(script Script) CallbackChannelFunc func(script Script, c chan func()) }
ScriptModuleDefinition groups multiple functions
func (*ScriptModuleDefinition) FunctionDef ¶
func (s *ScriptModuleDefinition) FunctionDef() map[string]api.Function
FunctionDef returns function definitions for module
type SensorItem ¶
type SensorItem interface { ValuesItem // GetValues of sensor GetValues() map[string]interface{} }
SensorItem provides the functionality to read values
func GetSensorItem ¶
func GetSensorItem(item Item) (SensorItem, bool)
GetSensorItem return the sensor item if item is a sensor
type SensorItemChecker ¶
type SensorItemChecker interface { // IsSensorItem returns true if item is a sensor IsSensorItem() bool }
SensorItemChecker provides interface to check if sensor item
type SensorItemSingle ¶
type SensorItemSingle interface { SensorItem // GetValue returns the given value GetValue(name string) interface{} }
SensorItemSingle provides the functionality to read a specific value
If not set this will be provided by item service
type Service ¶
type Service interface { // Key returns a unique identifier for this Service Key() string }
Service that can be registered to a bus
type ShutdownPlugin ¶
type ShutdownPlugin interface { Plugin // Shutdown called if plugin should be stopped Shutdown() }
ShutdownPlugin handles shutdown event
type ShutdownService ¶
ShutdownService -> a service that handle shutdown event
type SimplePathEntry ¶
type SimplePathEntry struct { // Definition of entry Def api.SimpleHandler // Path to this entry Path string // Method that this entry will handle Method string // Handler for this entry Handler SimplePathEntryHandler }
SimplePathEntry defines simpler path entry variant
func (SimplePathEntry) PathEntry ¶
func (s SimplePathEntry) PathEntry() PathEntry
PathEntry created from simple entry
type SimplePathEntryHandler ¶
SimplePathEntryHandler handles simple path entries
type StartService ¶
type StartService interface { Service // called if all plugins and services are initialized Start(bus Bus) error }
StartService -> a service that handle start event
type TestBus ¶
type TestBus struct { StartFunc func() error ShutdownFunc func() RegisterServiceFunc func(Service) error HandleRequestFunc func(Request) HandleRequestWaitFunc func(Request, time.Duration) Response RegisterEventListenerFunc func(string, chan Event) error UnregisterEventListenerFunc func(string, chan Event) }
TestBus implements a bus for units testing
func (*TestBus) HandleRequest ¶
HandleRequest forwards the request to the assigned service
func (*TestBus) HandleRequestWait ¶
HandleRequestWait handles request and wait for response
func (*TestBus) RegisterEventListener ¶
RegisterEventListener registers a new listener for the given key
func (*TestBus) RegisterService ¶
RegisterService to bus instance
func (*TestBus) Shutdown ¶
func (t *TestBus) Shutdown()
Shutdown bus and stop all services in reverse order of registration
func (*TestBus) UnregisterEventListener ¶
UnregisterEventListener remove the registered listener
type UpdateIntervalService ¶
type UpdateIntervalService interface { UpdateService // duration for update calls UpdateInterval() time.Duration }
UpdateIntervalService -> defines a custom interval for update events
type UpdateService ¶
type UpdateService interface { Service // called periodically (default: each minute) Update(bus Bus) }
UpdateService -> a service that handle update events
type ValuesItem ¶
ValuesItem is used by all items that can read or write values