kratos

package module
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

README

kratos, the client emulator

Build Status codecov.io Go Report Card Apache V2 License GitHub release PkgGoDev Quality Gate Status

Websocket wrapper that provides a simple API for making new connections, sending messages on that connection, and providing a way to handle received messages.

Table of Contents

Code of Conduct

This project and everyone participating in it are governed by the XMiDT Code Of Conduct. By participating, you agree to this Code.

How to Install

This project uses go modules to manage its dependencies. This is best used with go 1.12+. to import this module, run:

go get github.com/xmidt-org/kratos@latest

or add it to your go.mod file for your project.

Contributing

Refer to CONTRIBUTING.md.

Documentation

Index

Constants

View Source
const (
	StatusDeviceDisconnected int = 523
	StatusDeviceTimeout      int = 524
)

Variables

This section is empty.

Functions

func CreateErrorWRP

func CreateErrorWRP(transaction string, dest string, src string, statusCode int64, err error) *wrp.Message

func NewDecoderSender

func NewDecoderSender(sender registryHandler, maxWorkers int, queueSize int, logger log.Logger) *decoderQueue

NewDecoderSender creates a new decoderQueue for decoding and sending messages.

func NewDownstreamSender

func NewDownstreamSender(senderFunc sendWRPFunc, maxWorkers int, queueSize int, logger log.Logger) *downstreamSenderQueue

NewDownstreamSender creates a new downstreamSenderQueue for asynchronously sending wrp messages downstream.

func NewEncoderSender

func NewEncoderSender(sender outboundSender, maxWorkers int, queueSize int, logger log.Logger) *encoderQueue

NewEncoderSender creates a new encoderQueue, that allows for asynchronous sending outbound.

func NewHandlerRegistry

func NewHandlerRegistry(config []HandlerConfig) (*handlerRegistry, error)

NewHandlerRegistry creates a handlerRegistry based on the initial handlers given.

func NewRegistryHandler

func NewRegistryHandler(senderFunc sendWRPFunc, registry HandlerRegistry, downstreamSender downstreamSender, maxWorkers int, queueSize int, deviceID string, logger log.Logger) *registryQueue

NewRegistryHandler returns a registryHandler, which sends wrp messages to the correct handler in an asynchronous fashion.

func NewSender

func NewSender(connection websocketConnection, maxWorkers int, queueSize int, logger log.Logger) *senderQueue

NewSender creates a new senderQueue with the given websocketConnection and other configuration.

Types

type Client

type Client interface {
	Hostname() string
	HandlerRegistry() HandlerRegistry
	Send(message *wrp.Message)
	Close() error
}

Client is what function calls we expose to the user of kratos

func NewClient

func NewClient(config ClientConfig) (Client, error)

NewClient is used to create a new kratos Client from a ClientConfig.

type ClientConfig

type ClientConfig struct {
	DeviceName           string
	FirmwareName         string
	ModelName            string
	Manufacturer         string
	DestinationURL       string
	Token                string
	OutboundQueue        QueueConfig
	WRPEncoderQueue      QueueConfig
	WRPDecoderQueue      QueueConfig
	HandlerRegistryQueue QueueConfig
	HandleMsgQueue       QueueConfig
	TlsConfig            *tls.Config
	Handlers             []HandlerConfig
	HandlePingMiss       HandlePingMiss
	ClientLogger         log.Logger
	PingConfig           PingConfig
}

ClientConfig is the configuration to provide when making a new client.

type DownstreamHandler

type DownstreamHandler interface {
	HandleMessage(msg *wrp.Message) *wrp.Message
	Close()
}

DownstreamHandler should be implemented by the user so that they may deal with received messages how they please.

type ErrInvalidHandler

type ErrInvalidHandler interface {
	ErrInvalidHandler()
}

ErrInvalidHandler provides an easy way for a consumer to do logic based on the error of an invalid handler being found.

type ErrNoDownstreamHandler

type ErrNoDownstreamHandler interface {
	ErrNoDownstreamHandler()
}

ErrNoDownstreamHandler provides an easy way for a consumer to do logic based on the error of no downstream handler being found.

type HandlePingMiss

type HandlePingMiss func() error

HandlePingMiss is a function called when we run into situations where we're not getting anymore pings. The implementation of this function needs to be handled by the user of kratos.

type HandlerConfig

type HandlerConfig struct {
	Regexp  string
	Handler DownstreamHandler
}

HandlerConfig is the values that a consumer can set that specify the handler to use for the regular expression.

type HandlerGroup

type HandlerGroup struct {
	// contains filtered or unexported fields
}

HandlerGroup is an internal data type for Client interface that helps keep track of registered handler functions.

type HandlerRegistry

type HandlerRegistry interface {
	Add(string, DownstreamHandler) error
	Remove(string)
	GetHandler(string) (DownstreamHandler, error)
	Close()
}

HandlerRegistry is an interface that handles adding, getting, and removing DownstreamHandlers.

type Message

type Message struct {
	Code int    `json:"code"`
	Body string `json:"body"`
}

func (Message) String

func (msg Message) String() string

type MessageBodyer

type MessageBodyer interface {
	MessageBody() string
}

type PingConfig

type PingConfig struct {
	PingWait        time.Duration
	MaxPingMiss     int
	ReconnectOnMiss bool
}

type QueueConfig

type QueueConfig struct {
	MaxWorkers int
	Size       int
}

QueueConfig is used to configure all the queues used to make kratos asynchronous.

type StatusCoder

type StatusCoder interface {
	StatusCode() int
}

statusCode follows the go-kit convention. Errors and other objects that implement this interface are allowed to supply an HTTP response status code.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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