service

package
v0.0.0-...-726e4b6 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMQTTClient = errors.New("no mqtt client")
View Source
var TedgeBinary = "tedge"

Functions

func DisplayMessage

func DisplayMessage(name string, in, out *streamer.OutputMessage, w io.Writer, compact bool, useColor bool) bool

func NewMetaData

func NewMetaData(defaults ...MetaOption) map[string]any

func SendAPIRequest

func SendAPIRequest(client *APIClient, host, method, path string, body any) (err error)

func WithMQTTPublisher

func WithMQTTPublisher(client mqtt.Client, topic string, qos byte, retain bool, message any) func()

func WithRESTRequest

func WithRESTRequest(client *APIClient, host, method, path string, message any) func()

func WithSettings

func WithSettings(opts ...SettingOption) string

Types

type APIClient

type APIClient struct {
	*c8y.Client
}

func NewCumulocityClient

func NewCumulocityClient(host string) *APIClient

func (*APIClient) SendRequest

func (c *APIClient) SendRequest(ctx context.Context, options c8y.RequestOptions) (*c8y.Response, error)

type DefaultServiceOptions

type DefaultServiceOptions struct {
	Broker                     string
	ClientID                   string
	CleanSession               bool
	HTTPEndpoint               string
	RouteDirs                  []string
	MaxRouteDepth              int
	PostMessageDelay           time.Duration
	Debug                      bool
	DryRun                     bool
	MetaOptions                []MetaOption
	LibraryPaths               []string
	UseColor                   bool
	EntityFile                 string
	EnableRegistrationListener bool
}

type Entity

type Entity struct {
	ID          string          `json:"@id"`
	EntityType  string          `json:"@type"`
	ParentID    string          `json:"@parent"`
	Type        string          `json:"type"`
	DisplayName string          `json:"displayName"`
	Contents    []EntityContent `json:"contents,omitempty"`
}

type EntityContent

type EntityContent struct {
	ID     string `json:"@id"`
	Type   string `json:"@type"`
	Value  string `json:"value"`
	Schema string `json:"schema"`
}

type EntityStore

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

func NewEntityStore

func NewEntityStore() *EntityStore

func (*EntityStore) Get

func (s *EntityStore) Get(key string) (Entity, error)

func (*EntityStore) SerializedEntities

func (s *EntityStore) SerializedEntities() []byte

func (*EntityStore) Set

func (s *EntityStore) Set(key string, entity Entity) error

func (*EntityStore) SetFromJSON

func (s *EntityStore) SetFromJSON(content []byte, deleteExisting bool, ignoreErrors bool) error

Update multiple entities from json

type MessageHandler

type MessageHandler func(topic string, message_in string) (message_out *streamer.OutputMessage, err error)

func NewStreamFactory

func NewStreamFactory(client mqtt.Client, apiClient *APIClient, route routes.Route, variablesFactory VariablesFactory, maxDepth int, postDelay time.Duration, opts ...jsonnet.TemplateOption) MessageHandler

type MetaOption

type MetaOption func(m map[string]any)

func WithMetaDefaultDeviceID

func WithMetaDefaultDeviceID(value string) MetaOption

func WithMetaDefaultValue

func WithMetaDefaultValue(key string, value any) MetaOption

func WithMetaHostname

func WithMetaHostname() MetaOption

type Service

type Service struct {
	Client        mqtt.Client
	APIClient     *APIClient
	Subscriptions map[string]byte
	Routes        []routes.Route
	EntityStore   *EntityStore
}

func NewDefaultService

func NewDefaultService(opts *DefaultServiceOptions) (*Service, error)

func NewService

func NewService(broker string, clientID string, cleanSession bool, httpEndpoint string, dryRun bool) (*Service, error)

func (*Service) ClearRoutes

func (s *Service) ClearRoutes()

func (*Service) GetRoutes

func (s *Service) GetRoutes() []routes.Route

func (*Service) GetVariables

func (s *Service) GetVariables() string

func (*Service) Register

func (s *Service) Register(topics []string, qos byte, handler MessageHandler) error

func (*Service) ScanMappingFiles

func (s *Service) ScanMappingFiles(dirs []string) []routes.Route

Scan for routes from a directory. It will automatically add routes to the existing list. Use an explicit call to ClearRoutes if you want to clear existing routes before calling this function. Note: Currently routes are not unregistered from the MQTT client. For this to occur the MQTT client needs to be stopped and destroyed.

func (*Service) StartSubscriptions

func (s *Service) StartSubscriptions() error

type SettingOption

type SettingOption func() string

func WithEnvironment

func WithEnvironment(key string) SettingOption

Get an environment variable

func WithTedgeSetting

func WithTedgeSetting(key string) SettingOption

Get a configuration value from thin-edge.io using the tedge cli

func WithValue

func WithValue(value string) SettingOption

Get an override value

type VariablesFactory

type VariablesFactory func() string

Jump to

Keyboard shortcuts

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