realtime

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const TypeWS = "ws"

Variables

View Source
var (
	// ErrInvalidMessage indicates that a message payload was not valid.
	ErrInvalidMessage = errors.New("message type not binary")
)
View Source
var HooksGroupName = "mqtt_hooks"
View Source
var ListenersGroupName = "mqtt_listeners"

Functions

func AllowHook

func AllowHook(ms *MqttServer) error

func AppendHooks

func AppendHooks(ms *MqttServer, hooks ...mqtt.Hook) error

func AppendListeners

func AppendListeners(ms *MqttServer, listeners ...listeners.Listener) error

func Module

func Module(opts ...di.Node) di.Node

Types

type Authorizer

type Authorizer interface {
	Authorize() fiber.Handler
}

func NewAuthorizer

func NewAuthorizer(logger *zap.Logger) Authorizer

type Broker added in v1.2.0

type Broker interface {
	Publisher
	Subscriber
}

type MockAuthorizer added in v1.2.0

type MockAuthorizer struct {
	mock.Mock
}

MockAuthorizer is an autogenerated mock type for the Authorizer type

func NewMockAuthorizer added in v1.2.0

func NewMockAuthorizer(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockAuthorizer

NewMockAuthorizer creates a new instance of MockAuthorizer. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAuthorizer) Authorize added in v1.2.0

func (_mock *MockAuthorizer) Authorize() fiber.Handler

Authorize provides a mock function for the type MockAuthorizer

func (*MockAuthorizer) EXPECT added in v1.2.0

type MockAuthorizer_Authorize_Call added in v1.2.0

type MockAuthorizer_Authorize_Call struct {
	*mock.Call
}

MockAuthorizer_Authorize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Authorize'

func (*MockAuthorizer_Authorize_Call) Return added in v1.2.0

func (*MockAuthorizer_Authorize_Call) Run added in v1.2.0

func (*MockAuthorizer_Authorize_Call) RunAndReturn added in v1.2.0

type MockAuthorizer_Expecter added in v1.2.0

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

func (*MockAuthorizer_Expecter) Authorize added in v1.2.0

Authorize is a helper method to define mock.On call

type MockBroker added in v1.2.0

type MockBroker struct {
	mock.Mock
}

MockBroker is an autogenerated mock type for the Broker type

func NewMockBroker added in v1.2.0

func NewMockBroker(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockBroker

NewMockBroker creates a new instance of MockBroker. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockBroker) EXPECT added in v1.2.0

func (_m *MockBroker) EXPECT() *MockBroker_Expecter

func (*MockBroker) Publish added in v1.2.0

func (_mock *MockBroker) Publish(topic string, payload any, retain bool, qos byte) error

Publish provides a mock function for the type MockBroker

func (*MockBroker) Subscribe added in v1.2.0

func (_mock *MockBroker) Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error

Subscribe provides a mock function for the type MockBroker

func (*MockBroker) Unsubscribe added in v1.2.0

func (_mock *MockBroker) Unsubscribe(filter string, subscriptionId int) error

Unsubscribe provides a mock function for the type MockBroker

type MockBroker_Expecter added in v1.2.0

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

func (*MockBroker_Expecter) Publish added in v1.2.0

func (_e *MockBroker_Expecter) Publish(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockBroker_Publish_Call

Publish is a helper method to define mock.On call

  • topic string
  • payload any
  • retain bool
  • qos byte

func (*MockBroker_Expecter) Subscribe added in v1.2.0

func (_e *MockBroker_Expecter) Subscribe(filter interface{}, subscriptionId interface{}, handler interface{}) *MockBroker_Subscribe_Call

Subscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int
  • handler mqtt.InlineSubFn

func (*MockBroker_Expecter) Unsubscribe added in v1.2.0

func (_e *MockBroker_Expecter) Unsubscribe(filter interface{}, subscriptionId interface{}) *MockBroker_Unsubscribe_Call

Unsubscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int

type MockBroker_Publish_Call added in v1.2.0

type MockBroker_Publish_Call struct {
	*mock.Call
}

MockBroker_Publish_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Publish'

func (*MockBroker_Publish_Call) Return added in v1.2.0

func (*MockBroker_Publish_Call) Run added in v1.2.0

func (_c *MockBroker_Publish_Call) Run(run func(topic string, payload any, retain bool, qos byte)) *MockBroker_Publish_Call

func (*MockBroker_Publish_Call) RunAndReturn added in v1.2.0

func (_c *MockBroker_Publish_Call) RunAndReturn(run func(topic string, payload any, retain bool, qos byte) error) *MockBroker_Publish_Call

type MockBroker_Subscribe_Call added in v1.2.0

type MockBroker_Subscribe_Call struct {
	*mock.Call
}

MockBroker_Subscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Subscribe'

func (*MockBroker_Subscribe_Call) Return added in v1.2.0

func (*MockBroker_Subscribe_Call) Run added in v1.2.0

func (_c *MockBroker_Subscribe_Call) Run(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn)) *MockBroker_Subscribe_Call

func (*MockBroker_Subscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockBroker_Subscribe_Call) RunAndReturn(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn) error) *MockBroker_Subscribe_Call

type MockBroker_Unsubscribe_Call added in v1.2.0

type MockBroker_Unsubscribe_Call struct {
	*mock.Call
}

MockBroker_Unsubscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unsubscribe'

func (*MockBroker_Unsubscribe_Call) Return added in v1.2.0

func (*MockBroker_Unsubscribe_Call) Run added in v1.2.0

func (_c *MockBroker_Unsubscribe_Call) Run(run func(filter string, subscriptionId int)) *MockBroker_Unsubscribe_Call

func (*MockBroker_Unsubscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockBroker_Unsubscribe_Call) RunAndReturn(run func(filter string, subscriptionId int) error) *MockBroker_Unsubscribe_Call

type MockPublisher added in v1.2.0

type MockPublisher struct {
	mock.Mock
}

MockPublisher is an autogenerated mock type for the Publisher type

func NewMockPublisher added in v1.2.0

func NewMockPublisher(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockPublisher

NewMockPublisher creates a new instance of MockPublisher. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockPublisher) EXPECT added in v1.2.0

func (_m *MockPublisher) EXPECT() *MockPublisher_Expecter

func (*MockPublisher) Publish added in v1.2.0

func (_mock *MockPublisher) Publish(topic string, payload any, retain bool, qos byte) error

Publish provides a mock function for the type MockPublisher

type MockPublisher_Expecter added in v1.2.0

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

func (*MockPublisher_Expecter) Publish added in v1.2.0

func (_e *MockPublisher_Expecter) Publish(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockPublisher_Publish_Call

Publish is a helper method to define mock.On call

  • topic string
  • payload any
  • retain bool
  • qos byte

type MockPublisher_Publish_Call added in v1.2.0

type MockPublisher_Publish_Call struct {
	*mock.Call
}

MockPublisher_Publish_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Publish'

func (*MockPublisher_Publish_Call) Return added in v1.2.0

func (*MockPublisher_Publish_Call) Run added in v1.2.0

func (_c *MockPublisher_Publish_Call) Run(run func(topic string, payload any, retain bool, qos byte)) *MockPublisher_Publish_Call

func (*MockPublisher_Publish_Call) RunAndReturn added in v1.2.0

func (_c *MockPublisher_Publish_Call) RunAndReturn(run func(topic string, payload any, retain bool, qos byte) error) *MockPublisher_Publish_Call

type MockSubscriber added in v1.2.0

type MockSubscriber struct {
	mock.Mock
}

MockSubscriber is an autogenerated mock type for the Subscriber type

func NewMockSubscriber added in v1.2.0

func NewMockSubscriber(t interface {
	mock.TestingT
	Cleanup(func())
}) *MockSubscriber

NewMockSubscriber creates a new instance of MockSubscriber. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockSubscriber) EXPECT added in v1.2.0

func (*MockSubscriber) Subscribe added in v1.2.0

func (_mock *MockSubscriber) Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error

Subscribe provides a mock function for the type MockSubscriber

func (*MockSubscriber) Unsubscribe added in v1.2.0

func (_mock *MockSubscriber) Unsubscribe(filter string, subscriptionId int) error

Unsubscribe provides a mock function for the type MockSubscriber

type MockSubscriber_Expecter added in v1.2.0

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

func (*MockSubscriber_Expecter) Subscribe added in v1.2.0

func (_e *MockSubscriber_Expecter) Subscribe(filter interface{}, subscriptionId interface{}, handler interface{}) *MockSubscriber_Subscribe_Call

Subscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int
  • handler mqtt.InlineSubFn

func (*MockSubscriber_Expecter) Unsubscribe added in v1.2.0

func (_e *MockSubscriber_Expecter) Unsubscribe(filter interface{}, subscriptionId interface{}) *MockSubscriber_Unsubscribe_Call

Unsubscribe is a helper method to define mock.On call

  • filter string
  • subscriptionId int

type MockSubscriber_Subscribe_Call added in v1.2.0

type MockSubscriber_Subscribe_Call struct {
	*mock.Call
}

MockSubscriber_Subscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Subscribe'

func (*MockSubscriber_Subscribe_Call) Return added in v1.2.0

func (*MockSubscriber_Subscribe_Call) Run added in v1.2.0

func (_c *MockSubscriber_Subscribe_Call) Run(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn)) *MockSubscriber_Subscribe_Call

func (*MockSubscriber_Subscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockSubscriber_Subscribe_Call) RunAndReturn(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn) error) *MockSubscriber_Subscribe_Call

type MockSubscriber_Unsubscribe_Call added in v1.2.0

type MockSubscriber_Unsubscribe_Call struct {
	*mock.Call
}

MockSubscriber_Unsubscribe_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Unsubscribe'

func (*MockSubscriber_Unsubscribe_Call) Return added in v1.2.0

func (*MockSubscriber_Unsubscribe_Call) Run added in v1.2.0

func (_c *MockSubscriber_Unsubscribe_Call) Run(run func(filter string, subscriptionId int)) *MockSubscriber_Unsubscribe_Call

func (*MockSubscriber_Unsubscribe_Call) RunAndReturn added in v1.2.0

func (_c *MockSubscriber_Unsubscribe_Call) RunAndReturn(run func(filter string, subscriptionId int) error) *MockSubscriber_Unsubscribe_Call

type MqttServer

type MqttServer struct {
	*mqtt.Server
}

func NewMqttServer

func NewMqttServer() (*MqttServer, error)

func (*MqttServer) Publish added in v1.2.0

func (m *MqttServer) Publish(topic string, payload any, retain bool, qos byte) error

func (*MqttServer) Start

func (m *MqttServer) Start(context.Context) error

func (*MqttServer) Stop

func (m *MqttServer) Stop(context.Context) error

type Option added in v1.2.0

type Option func(*Websocket)

Option customizes a Websocket instance.

func WithApp added in v1.2.0

func WithApp(app fiber.Router) Option

WithApp sets the Fiber router for registering the websocket handler.

func WithAuthorizer added in v1.2.0

func WithAuthorizer(authorizer Authorizer) Option

WithAuthorizer sets the authorizer for the websocket handler.

func WithId added in v1.2.0

func WithId(id string) Option

WithId sets the Websocket listener id.

func WithPath added in v1.2.0

func WithPath(path string) Option

WithPath sets the route path for the websocket handler.

func WithUpgrader added in v1.2.0

func WithUpgrader(upgrader *websocket.Upgrader) Option

WithUpgrader sets the websocket upgrader.

type Publisher added in v1.2.0

type Publisher interface {
	Publish(topic string, payload any, retain bool, qos byte) error
}

type Subscriber added in v1.2.0

type Subscriber interface {
	Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error
	Unsubscribe(filter string, subscriptionId int) error
}

type Websocket

type Websocket struct {
	sync.RWMutex
	Id          string       // the internal id of the listener
	App         fiber.Router // the fiber router to register the websocket handler on
	Authorizer  Authorizer
	Path        string
	Log         *slog.Logger          // server logging
	EstablishFn listeners.EstablishFn // the server's establish connection handler
	Upgrader    *websocket.Upgrader   //  upgrade the incoming http/tcp connection to a websocket compliant connection.
}

Websocket is a listener for establishing websocket connections.

func NewWebsocket

func NewWebsocket(app fiber.Router, authorizer Authorizer) *Websocket

NewWebsocket initializes and returns a new Websocket listener, listening on an address.

func NewWebsocketWithOptions added in v1.2.0

func NewWebsocketWithOptions(opts ...Option) *Websocket

NewWebsocketWithOptions initializes a Websocket with defaults and applies options.

func (*Websocket) Address

func (l *Websocket) Address() string

Address returns the address of the listener.

func (*Websocket) Close

func (l *Websocket) Close(closeClients listeners.CloseFn)

Close closes the listener and any client connections.

func (*Websocket) Handle

func (l *Websocket) Handle(r fiber.Router)

func (*Websocket) Handler added in v1.2.0

func (l *Websocket) Handler(w http.ResponseWriter, r *http.Request)

Handler upgrades and handles an incoming websocket connection.

func (*Websocket) ID

func (l *Websocket) ID() string

ID returns the id of the listener.

func (*Websocket) Init

func (l *Websocket) Init(log *slog.Logger) error

Init initializes the listener.

func (*Websocket) Protocol

func (l *Websocket) Protocol() string

Protocol returns the address of the listener.

func (*Websocket) Serve

func (l *Websocket) Serve(establish listeners.EstablishFn)

Serve starts waiting for new Websocket connections, and calls the connection establishment callback for any received.

Jump to

Keyboard shortcuts

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