Documentation
¶
Index ¶
- Constants
- Variables
- func AppendHooks(ms *MqttServer, hooks ...mqtt.Hook) error
- func AppendListeners(ms *MqttServer, listeners ...listeners.Listener) error
- func Module(opts ...di.Node) di.Node
- func UseAllowHook() di.Node
- func UseWebsocketListener(opts ...Option) di.Node
- type Authorizer
- type Broker
- type MockAuthorizer
- type MockAuthorizer_Authorize_Call
- type MockAuthorizer_Expecter
- type MockBroker
- func (_m *MockBroker) EXPECT() *MockBroker_Expecter
- func (_mock *MockBroker) Publish(topic string, payload any, retain bool, qos byte) error
- func (_mock *MockBroker) Subscribe(filter string, subscriptionId int, handler mqtt.InlineSubFn) error
- func (_mock *MockBroker) Unsubscribe(filter string, subscriptionId int) error
- type MockBroker_Expecter
- func (_e *MockBroker_Expecter) Publish(topic interface{}, payload interface{}, retain interface{}, qos interface{}) *MockBroker_Publish_Call
- func (_e *MockBroker_Expecter) Subscribe(filter interface{}, subscriptionId interface{}, handler interface{}) *MockBroker_Subscribe_Call
- func (_e *MockBroker_Expecter) Unsubscribe(filter interface{}, subscriptionId interface{}) *MockBroker_Unsubscribe_Call
- type MockBroker_Publish_Call
- func (_c *MockBroker_Publish_Call) Return(err error) *MockBroker_Publish_Call
- func (_c *MockBroker_Publish_Call) Run(run func(topic string, payload any, retain bool, qos byte)) *MockBroker_Publish_Call
- func (_c *MockBroker_Publish_Call) RunAndReturn(run func(topic string, payload any, retain bool, qos byte) error) *MockBroker_Publish_Call
- type MockBroker_Subscribe_Call
- func (_c *MockBroker_Subscribe_Call) Return(err error) *MockBroker_Subscribe_Call
- func (_c *MockBroker_Subscribe_Call) Run(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn)) *MockBroker_Subscribe_Call
- func (_c *MockBroker_Subscribe_Call) RunAndReturn(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn) error) *MockBroker_Subscribe_Call
- type MockBroker_Unsubscribe_Call
- func (_c *MockBroker_Unsubscribe_Call) Return(err error) *MockBroker_Unsubscribe_Call
- func (_c *MockBroker_Unsubscribe_Call) Run(run func(filter string, subscriptionId int)) *MockBroker_Unsubscribe_Call
- func (_c *MockBroker_Unsubscribe_Call) RunAndReturn(run func(filter string, subscriptionId int) error) *MockBroker_Unsubscribe_Call
- type MockPublisher
- type MockPublisher_Expecter
- type MockPublisher_Publish_Call
- func (_c *MockPublisher_Publish_Call) Return(err error) *MockPublisher_Publish_Call
- func (_c *MockPublisher_Publish_Call) Run(run func(topic string, payload any, retain bool, qos byte)) *MockPublisher_Publish_Call
- func (_c *MockPublisher_Publish_Call) RunAndReturn(run func(topic string, payload any, retain bool, qos byte) error) *MockPublisher_Publish_Call
- type MockSubscriber
- type MockSubscriber_Expecter
- type MockSubscriber_Subscribe_Call
- func (_c *MockSubscriber_Subscribe_Call) Return(err error) *MockSubscriber_Subscribe_Call
- func (_c *MockSubscriber_Subscribe_Call) Run(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn)) *MockSubscriber_Subscribe_Call
- func (_c *MockSubscriber_Subscribe_Call) RunAndReturn(run func(filter string, subscriptionId int, handler mqtt.InlineSubFn) error) *MockSubscriber_Subscribe_Call
- type MockSubscriber_Unsubscribe_Call
- func (_c *MockSubscriber_Unsubscribe_Call) Return(err error) *MockSubscriber_Unsubscribe_Call
- func (_c *MockSubscriber_Unsubscribe_Call) Run(run func(filter string, subscriptionId int)) *MockSubscriber_Unsubscribe_Call
- func (_c *MockSubscriber_Unsubscribe_Call) RunAndReturn(run func(filter string, subscriptionId int) error) *MockSubscriber_Unsubscribe_Call
- type MqttServer
- type Option
- type Publisher
- type Subscriber
- type Websocket
- func (l *Websocket) Address() string
- func (l *Websocket) Close(closeClients listeners.CloseFn)
- func (l *Websocket) Handle(r fiber.Router)
- func (l *Websocket) Handler(w http.ResponseWriter, r *http.Request)
- func (l *Websocket) ID() string
- func (l *Websocket) Init(log *slog.Logger) error
- func (l *Websocket) Protocol() string
- func (l *Websocket) Serve(establish listeners.EstablishFn)
Constants ¶
const TypeWS = "ws"
Variables ¶
var ( // ErrInvalidMessage indicates that a message payload was not valid. ErrInvalidMessage = errors.New("message type not binary") )
var HooksGroupName = "mqtt_hooks"
var ListenersGroupName = "mqtt_listeners"
Functions ¶
func AppendHooks ¶
func AppendHooks(ms *MqttServer, hooks ...mqtt.Hook) error
func AppendListeners ¶
func AppendListeners(ms *MqttServer, listeners ...listeners.Listener) error
func UseAllowHook ¶ added in v1.4.0
func UseWebsocketListener ¶ added in v1.4.0
Types ¶
type Authorizer ¶
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
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
func (_m *MockAuthorizer) EXPECT() *MockAuthorizer_Expecter
type MockAuthorizer_Authorize_Call ¶ added in v1.2.0
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 (_c *MockAuthorizer_Authorize_Call) Return(v fiber.Handler) *MockAuthorizer_Authorize_Call
func (*MockAuthorizer_Authorize_Call) Run ¶ added in v1.2.0
func (_c *MockAuthorizer_Authorize_Call) Run(run func()) *MockAuthorizer_Authorize_Call
func (*MockAuthorizer_Authorize_Call) RunAndReturn ¶ added in v1.2.0
func (_c *MockAuthorizer_Authorize_Call) RunAndReturn(run func() fiber.Handler) *MockAuthorizer_Authorize_Call
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
func (_e *MockAuthorizer_Expecter) Authorize() *MockAuthorizer_Authorize_Call
Authorize is a helper method to define mock.On call
type MockBroker ¶ added in v1.2.0
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
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
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 (_c *MockBroker_Publish_Call) Return(err error) *MockBroker_Publish_Call
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
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 (_c *MockBroker_Subscribe_Call) Return(err error) *MockBroker_Subscribe_Call
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
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 (_c *MockBroker_Unsubscribe_Call) Return(err error) *MockBroker_Unsubscribe_Call
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
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
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
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 (_c *MockPublisher_Publish_Call) Return(err error) *MockPublisher_Publish_Call
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
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 (_m *MockSubscriber) EXPECT() *MockSubscriber_Expecter
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
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 (_c *MockSubscriber_Subscribe_Call) Return(err error) *MockSubscriber_Subscribe_Call
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
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 (_c *MockSubscriber_Unsubscribe_Call) Return(err error) *MockSubscriber_Unsubscribe_Call
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 ¶
func NewMqttServer ¶
func NewMqttServer() (*MqttServer, error)
type Option ¶ added in v1.2.0
type Option func(*Websocket)
Option customizes a Websocket instance.
func WithAuthorizer ¶ added in v1.2.0
func WithAuthorizer(authorizer Authorizer) Option
WithAuthorizer sets the authorizer for the websocket handler.
func WithUpgrader ¶ added in v1.2.0
WithUpgrader sets the websocket upgrader.
type Subscriber ¶ added in v1.2.0
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
NewWebsocketWithOptions initializes a Websocket with defaults and applies options.
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) Serve ¶
func (l *Websocket) Serve(establish listeners.EstablishFn)
Serve starts waiting for new Websocket connections, and calls the connection establishment callback for any received.