messanger

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2025 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Topics    TopicList
	TopicBase string
)

Functions

func TopicControl

func TopicControl(topic string) string

func TopicData

func TopicData(topic string) string

Types

type Callback

type Callback func(msg *Msg)

type MQTT

type MQTT struct {
	ID     string `json:"id"`
	Broker string `json:"broker"`
	Debug  bool   `json:"debug"`

	Subscribers map[string][]MsgHandle `json:"subscribers"`
	Publishers  map[string]int         `json:"publishers"`

	gomqtt.Client `json:"-"`
}

MQTT is a wrapper around the Paho MQTT Go package Wraps the Broker, ID and Debug variables.

func GetMQTT

func GetMQTT() *MQTT

func NewMQTT

func NewMQTT() *MQTT

NewMQTT creates a new instance of the MQTT client type.

func SetMQTTClient added in v0.0.7

func SetMQTTClient(c gomqtt.Client) *MQTT

func (*MQTT) Connect

func (m *MQTT) Connect() error

Connect to the MQTT broker after setting some MQTT options then connecting to the MQTT broker

func (*MQTT) IsConnected

func (m *MQTT) IsConnected() bool

IsConnected will tell you if the MQTT client is connected to the specified broker

func (MQTT) Publish

func (m MQTT) Publish(topic string, value interface{})

Publish will publish a value to the given channel

func (MQTT) PublishMsg added in v0.0.7

func (m MQTT) PublishMsg(msg *Msg)

Publish messanger will publish a messanger

func (MQTT) ServeHTTP

func (mqtt MQTT) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*MQTT) Subscribe

func (m *MQTT) Subscribe(topic string, f MsgHandle) error

Subscribe will cause messangers to the given topic to be passed along to the MsgHandle f

type MQTTPrinter

type MQTTPrinter struct {
}

MQTTPrinter defines the struct that simply prints what ever message is sent to a given topic

func (*MQTTPrinter) Callback

func (mp *MQTTPrinter) Callback(msg *Msg)

Callback will print out all messages sent to the given topic from the MQTTPrinter

type Message added in v0.0.7

type Message interface {
}

type Messanger

type Messanger interface {
	Publisher()
	Subscriber()
}

Messanger represents a type that can publish and subscribe to messages

type MockClient

type MockClient struct {
	Subscribers map[string]Sub
	// contains filtered or unexported fields
}

func GetMockClient

func GetMockClient() *MockClient

func (*MockClient) AddRoute

func (m *MockClient) AddRoute(topic string, callback gomqtt.MessageHandler)

func (*MockClient) Connect

func (m *MockClient) Connect() gomqtt.Token

func (*MockClient) Disconnect

func (m *MockClient) Disconnect(quiecense uint)

func (*MockClient) IsConnected

func (m *MockClient) IsConnected() bool

func (*MockClient) IsConnectionOpen

func (m *MockClient) IsConnectionOpen() bool

func (*MockClient) MessageHandler

func (m *MockClient) MessageHandler(c gomqtt.Client, mm gomqtt.Message)

func (*MockClient) OptionsReader

func (m *MockClient) OptionsReader() gomqtt.ClientOptionsReader

func (*MockClient) Publish

func (m *MockClient) Publish(topic string, qos byte, retained bool, payload interface{}) gomqtt.Token

func (*MockClient) Subscribe

func (m *MockClient) Subscribe(topic string, qos byte, mh gomqtt.MessageHandler) gomqtt.Token

func (*MockClient) SubscribeMultiple

func (m *MockClient) SubscribeMultiple(filters map[string]byte, callback gomqtt.MessageHandler) gomqtt.Token

func (*MockClient) Unsubscribe

func (m *MockClient) Unsubscribe(topics ...string) gomqtt.Token

type MockMessage

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

func (MockMessage) Ack

func (m MockMessage) Ack()

func (MockMessage) Duplicate

func (m MockMessage) Duplicate() bool

func (MockMessage) MessageID

func (m MockMessage) MessageID() uint16

func (MockMessage) Payload

func (m MockMessage) Payload() []byte

func (MockMessage) Qos

func (m MockMessage) Qos() byte

func (MockMessage) Retained

func (m MockMessage) Retained() bool

func (MockMessage) Topic

func (m MockMessage) Topic() string

type MockToken

type MockToken struct {
	Err error
}

func (MockToken) Done

func (t MockToken) Done() <-chan struct{}

func (MockToken) Error

func (t MockToken) Error() error

func (MockToken) Wait

func (t MockToken) Wait() bool

func (MockToken) WaitTimeout

func (t MockToken) WaitTimeout(d time.Duration) bool

type Msg added in v0.0.7

type Msg struct {
	ID     int64    `json:"id"`
	Topic  string   `json:"topic"`
	Path   []string `json:"path"`
	Args   []string `json:"args"`
	Data   []byte   `json:"msg"`
	Source string   `json:"source"`

	Timestamp time.Duration `json:"timestamp"`
}

Msg holds a value and some type of meta data to be pass around in the system.

func New added in v0.0.7

func New(topic string, data []byte, source string) *Msg

func (*Msg) Byte added in v0.0.7

func (msg *Msg) Byte() []byte

func (*Msg) Dump added in v0.0.7

func (msg *Msg) Dump() string

func (*Msg) Float64 added in v0.0.7

func (msg *Msg) Float64() float64

func (*Msg) IsJSON added in v0.0.7

func (msg *Msg) IsJSON() bool

func (*Msg) Last added in v0.0.7

func (msg *Msg) Last() string

func (*Msg) Map added in v0.0.7

func (msg *Msg) Map() (map[string]interface{}, error)

func (*Msg) Station added in v0.0.7

func (msg *Msg) Station() string

func (*Msg) String added in v0.0.7

func (msg *Msg) String() string

type MsgHandle

type MsgHandle func(msg *Msg)

Subscriber is an interface that defines a struct needs to have the Callback(topic string, data []byte) function defined.

type MsgSaver added in v0.0.7

type MsgSaver struct {
	Messages []*Msg `json:"saved-messages"`
	Saving   bool   `json:"saving"`
}

func GetMsgSaver added in v0.0.7

func GetMsgSaver() *MsgSaver

func (*MsgSaver) Dump added in v0.0.7

func (ms *MsgSaver) Dump()

func (*MsgSaver) ServeHTTP added in v0.0.7

func (ms *MsgSaver) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP will respond to the writer with 'Pong'

func (*MsgSaver) StartSaving added in v0.0.7

func (ms *MsgSaver) StartSaving()

func (*MsgSaver) StopSaving added in v0.0.7

func (ms *MsgSaver) StopSaving()

type Publisher

type Publisher interface {
	Publish(msg *Msg)
}

Publisher interface allows objects to publish message to a particular topic as defined in the message.Msg

type Sub

type Sub struct {
	ID    string
	Topic string
	Callback
}

type Subscriber

type Subscriber interface {
	Callback(msg *Msg)
}

Subscriber interface defines a type that can subscribe to published messages

type TopicList

type TopicList map[string]int

func (TopicList) ServeHTTP

func (t TopicList) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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