-
Notifications
You must be signed in to change notification settings - Fork 11
/
unsubscriber.go
32 lines (25 loc) · 1.09 KB
/
unsubscriber.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package courier
import (
"context"
)
// Unsubscriber defines behaviour of an MQTT client that can remove subscriptions.
type Unsubscriber interface {
// Unsubscribe removes any subscription to messages from an MQTT broker
Unsubscribe(ctx context.Context, topics ...string) error
}
type unsubscribeMiddleware interface {
// Middleware helps chain Unsubscriber(s).
Middleware(unsubscriber Unsubscriber) Unsubscriber
}
// UnsubscriberMiddlewareFunc functions are closures that intercept Unsubscriber.Unsubscribe calls.
type UnsubscriberMiddlewareFunc func(Unsubscriber) Unsubscriber
// Middleware allows UnsubscriberMiddlewareFunc to implement the unsubscribeMiddleware interface.
func (usmw UnsubscriberMiddlewareFunc) Middleware(unsubscriber Unsubscriber) Unsubscriber {
return usmw(unsubscriber)
}
// UnsubscriberFunc defines signature of a Unsubscribe function.
type UnsubscriberFunc func(context.Context, ...string) error
// Unsubscribe implements Unsubscriber interface on UnsubscriberFunc.
func (f UnsubscriberFunc) Unsubscribe(ctx context.Context, topics ...string) error {
return f(ctx, topics...)
}