messages

package module
v0.0.0-...-4e4a002 Latest Latest
Warning

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

Go to latest
Published: May 4, 2022 License: Apache-2.0 Imports: 3 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetJson

func GetJson(message Message) ([]byte, error)

GetJson converts message struct (event/alarm/metric) into json byte array suitable for sending to kafka bus

Types

type Alarm

type Alarm struct {
	Type      string    `json:"type"`
	Device    string    `json:"device,omitempty"`
	Message   string    `json:"message,omitempty"`
	Serverity uint      `json:"serverity,omitempty"`
	Timestamp time.Time `json:"timestamp,omitempty"`
}

The Alarm structure is meant to be a superset of all alarm message formats. The omitempty annotation will suppress marshalling unneeded fields

func (Alarm) MessageType

func (alarm Alarm) MessageType() MessageType

MessageType is required to satisfy the Message interface definition

type Event

type Event struct {
	Type      string    `json:"type"`
	Device    string    `json:"device,omitempty"`
	Message   string    `json:"message,omitempty"`
	Timestamp time.Time `json:"timestamp,omitempty"`
}

The Event structure is meant to be a superset of all event message formats. The omitempty annotation will suppress marshalling unneeded fields

func (Event) MessageType

func (event Event) MessageType() MessageType

MessageType is required to satisfy the Message interface definition

type Message

type Message interface {
	MessageType() MessageType
}

Message interface enables single functions to be used to process all types

func GetModel

func GetModel(messageType MessageType, msgJson []byte) (Message, error)

GetModel takes Json and unmarshals into appropriate message model

type MessageType

type MessageType int
const (
	ALARM MessageType = iota
	EVENT
	METRIC
)

type Metric

type Metric struct {
	Device    string    `json:"device"`
	BytesIn   uint64    `json:"bytes_in,omitempty"`
	BytesOut  uint64    `json:"bytes_out,omitempty"`
	ErrorsIn  uint64    `json:"errors_in,omitempty"`
	ErrorsOut uint64    `json:"errors_out,omitempty"`
	Timestamp time.Time `json:"timestamp,omitempty"`
}

The Metric structure is meant to be a superset of all metric message formats. The omitempty annotation will suppress marshalling unneeded fields

func (Metric) MessageType

func (metric Metric) MessageType() MessageType

MessageType is required to satisfy the Message interface definition

Jump to

Keyboard shortcuts

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