Documentation ¶
Overview ¶
Package server implements extension hub, which manages all incoming connections from extension controllers
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CmdSendFunc ¶
Stateful command send func, used to send command to and receive correspond message from the connected extension
type Config ¶ added in v0.3.0
type Config struct {
Endpoints []EndpointConfig
}
type EndpointConfig ¶ added in v0.3.0
type ExtensionContext ¶
type ExtensionContext struct { Context context.Context Name string SendCmd CmdSendFunc Codec codec.Interface // contains filtered or unexported fields }
ExtensionContext of one extension connection
func NewExtensionContext ¶
func NewExtensionContext( parent context.Context, name string, codec codec.Interface, sendCmd CmdSendFunc, ) *ExtensionContext
type ExtensionHandleFunc ¶
type ExtensionHandleFunc func(c *ExtensionContext)
Handle func for your own business logic
type ExtensionHandleFuncFactory ¶
type ExtensionHandleFuncFactory func(extensionName string) (ExtensionHandleFunc, OutOfBandMsgHandleFunc)
Func factory to create extension specific handle func
type ExtensionManager ¶
type ExtensionManager struct {
// contains filtered or unexported fields
}
func NewExtensionManager ¶
func NewExtensionManager( ctx context.Context, logger log.Interface, handleFuncFactory ExtensionHandleFuncFactory, ) *ExtensionManager
func (*ExtensionManager) HandleStream ¶ added in v0.3.0
func (m *ExtensionManager) HandleStream( name string, codec codec.Interface, keepaliveInterval time.Duration, messageTimeout time.Duration, stream io.ReadWriter, ) error
nolint:gocyclo
type OutOfBandMsgHandleFunc ¶
Handle message received from extension without previous command request, all messages passed to this function belongs to one extension
usually instance of this function type is used to handle extension events
e.g. lights turned off manually and detected by the extension
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func (*Server) Handle ¶
func (s *Server) Handle(kind arhatgopb.ExtensionType, handleFactory ExtensionHandleFuncFactory, extensions ...string)
Handle extension session with handleFunc, you can specify optional extension names (`extensions`) to restrict the handleFunc to these extensions, if no extension name specified, this handleFunc will override all existing handleFunc for extensions with this kind
func (*Server) ListenAndServe ¶
ListenAndServe listen on local addresses and accept connections from extensions