agent

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Path     = "./config.toml"
	Hearbeat = "channels.heartbeat.>"
	Commands = "commands"
)

Variables

View Source
var (

	// ErrMalformedEntity indicates malformed entity specification.
	ErrMalformedEntity = errors.New("malformed entity specification")

	// ErrInvalidQueryParams indicates malformed URL.
	ErrInvalidQueryParams = errors.New("invalid query params")
)

Functions

func SaveConfig

func SaveConfig(c Config) error

Save - store config in a file.

Types

type ChanConfig

type ChanConfig struct {
	Control string `toml:"control"`
	Data    string `toml:"data"`
}

type Config

type Config struct {
	Server    ServerConfig    `toml:"server" json:"server"`
	Terminal  TerminalConfig  `toml:"terminal" json:"terminal"`
	Heartbeat HeartbeatConfig `toml:"heartbeat" json:"heartbeat"`
	Channels  ChanConfig      `toml:"channels" json:"channels"`
	Edgex     EdgexConfig     `toml:"edgex" json:"edgex"`
	Log       LogConfig       `toml:"log" json:"log"`
	MQTT      MQTTConfig      `toml:"mqtt" json:"mqtt"`
	File      string
}

func ReadConfig

func ReadConfig(file string) (Config, error)

Read - retrieve config from a file.

type EdgexConfig

type EdgexConfig struct {
	URL string `toml:"url"`
}

type Heartbeat

type Heartbeat interface {
	Update()
	Info() Info
}

Heartbeat specifies api for updating status and keeping track on services that are sending heartbeat to NATS.

func NewHeartbeat

func NewHeartbeat(name, svcType string, interval time.Duration) Heartbeat

interval - duration of interval if service doesnt send heartbeat during interval it is marked offline.

type HeartbeatConfig

type HeartbeatConfig struct {
	Interval time.Duration `toml:"interval"`
}

func (*HeartbeatConfig) UnmarshalJSON

func (d *HeartbeatConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the duration from JSON.

type Info

type Info struct {
	Name     string    `json:"name"`
	LastSeen time.Time `json:"last_seen"`
	Status   string    `json:"status"`
	Type     string    `json:"type"`
	Terminal int       `json:"terminal"`
}

type LogConfig

type LogConfig struct {
	Level string `toml:"level"`
}

type MQTTConfig

type MQTTConfig struct {
	URL         string          `json:"url" toml:"url"`
	Username    string          `json:"username" toml:"username" mapstructure:"username"`
	Password    string          `json:"password" toml:"password" mapstructure:"password"`
	MTLS        bool            `json:"mtls" toml:"mtls" mapstructure:"mtls"`
	SkipTLSVer  bool            `json:"skip_tls_ver" toml:"skip_tls_ver" mapstructure:"skip_tls_ver"`
	Retain      bool            `json:"retain" toml:"retain" mapstructure:"retain"`
	QoS         byte            `json:"qos" toml:"qos" mapstructure:"qos"`
	CAPath      string          `json:"ca_path" toml:"ca_path" mapstructure:"ca_path"`
	CertPath    string          `json:"cert_path" toml:"cert_path" mapstructure:"cert_path"`
	PrivKeyPath string          `json:"priv_key_path" toml:"priv_key_path" mapstructure:"priv_key_path"`
	CA          []byte          `json:"-" toml:"-"`
	Cert        tls.Certificate `json:"-" toml:"-"`
	ClientCert  string          `json:"client_cert" toml:"client_cert"`
	ClientKey   string          `json:"client_key" toml:"client_key"`
	CaCert      string          `json:"ca_cert" toml:"ca_cert"`
}

type ServerConfig

type ServerConfig struct {
	Port      string `toml:"port" json:"port"`
	BrokerURL string `toml:"broker_url" json:"broker_url"`
}

type Service

type Service interface {
	// Execute command.
	Execute(string, string) (string, error)

	// Control command.
	Control(string, string) error

	// Update configuration file.
	AddConfig(Config) error

	// Config returns Config struct created from config file.
	Config() Config

	// Saves config file.
	ServiceConfig(ctx context.Context, uuid, cmdStr string) error

	// Services returns service list.
	Services() []Info

	// Terminal used for terminal control of gateway.
	Terminal(string, string) error

	// Publish message.
	Publish(string, string) error
}

Service specifies API for publishing messages and subscribing to topics.

func New

func New(ctx context.Context, mc paho.Client, cfg *Config, ec edgex.Client, broker messaging.PubSub, logger *slog.Logger) (Service, error)

New returns agent service implementation.

type TerminalConfig

type TerminalConfig struct {
	SessionTimeout time.Duration `toml:"session_timeout" json:"session_timeout"`
}

func (*TerminalConfig) UnmarshalJSON

func (d *TerminalConfig) UnmarshalJSON(b []byte) error

UnmarshalJSON parses the duration from JSON.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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