-
Notifications
You must be signed in to change notification settings - Fork 0
/
publisher.go
39 lines (31 loc) · 1.09 KB
/
publisher.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
33
34
35
36
37
38
39
//
// @project geniusrabbit.com 2015 – 2016, 2019 – 2022 - 2022
// @author Dmitry Ponomarev <[email protected]> 2015 – 2016, 2019 – 2022 - 2022
//
package notificationcenter
import (
"context"
"go.uber.org/multierr"
)
// Publisher pipeline base declaration
//go:generate mockgen -source $GOFILE -package mocks -destination mocks/publisher.go
type Publisher interface {
// Publish one or more messages to the pub-service
Publish(ctx context.Context, messages ...any) error
}
// MultiPublisher wrapper
type MultiPublisher []Publisher
// Publish one or more messages to the banch of pub-services
func (p MultiPublisher) Publish(ctx context.Context, messages ...any) error {
var errs error
for _, pub := range p {
errs = multierr.Append(errs, pub.Publish(ctx, messages...))
}
return errs
}
// FuncPublisher provides custom function wrapper for the custom publisher processor
type FuncPublisher func(context.Context, ...any) error
// Publish method call the original custom publisher function
func (f FuncPublisher) Publish(ctx context.Context, messages ...any) error {
return f(ctx, messages...)
}