server

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2021 License: Apache-2.0 Imports: 21 Imported by: 2

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

type CmdSendFunc func(cmd *arhatgopb.Cmd, waitForResponse bool) (*arhatgopb.Msg, error)

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 EndpointConfig struct {
	Listen            string
	TLS               *tls.Config
	KeepaliveInterval time.Duration
	MessageTimeout    time.Duration
}

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

func (*ExtensionContext) Close

func (c *ExtensionContext) Close()

Close extension connection

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

type OutOfBandMsgHandleFunc func(msg *arhatgopb.Msg)

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 NewServer

func NewServer(
	ctx context.Context,
	logger log.Interface,
	config *Config,
) (*Server, error)

func (*Server) Close added in v0.3.0

func (s *Server) Close()

Close all listening endpoints

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

func (s *Server) ListenAndServe() error

ListenAndServe listen on local addresses and accept connections from extensions

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL