forked from cloudevents/sdk-go
/
options.go
56 lines (47 loc) · 1.51 KB
/
options.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package amqp
import (
"github.com/ian-mi/sdk-go/v2/pkg/binding"
"pack.ag/amqp"
)
// Option is the function signature required to be considered an amqp.Option.
type Option func(*Protocol) error
// WithConnOpt sets a connection option for amqp
func WithConnOpt(opt amqp.ConnOption) Option {
return func(t *Protocol) error {
t.connOpts = append(t.connOpts, opt)
return nil
}
}
// WithConnSASLPlain sets SASLPlain connection option for amqp
func WithConnSASLPlain(username, password string) Option {
return WithConnOpt(amqp.ConnSASLPlain(username, password))
}
// WithSessionOpt sets a session option for amqp
func WithSessionOpt(opt amqp.SessionOption) Option {
return func(t *Protocol) error {
t.sessionOpts = append(t.sessionOpts, opt)
return nil
}
}
// WithSenderLinkOption sets a link option for amqp
func WithSenderLinkOption(opt amqp.LinkOption) Option {
return func(t *Protocol) error {
t.senderLinkOpts = append(t.senderLinkOpts, opt)
return nil
}
}
// WithReceiverLinkOption sets a link option for amqp
func WithReceiverLinkOption(opt amqp.LinkOption) Option {
return func(t *Protocol) error {
t.receiverLinkOpts = append(t.receiverLinkOpts, opt)
return nil
}
}
// amqp.Sender options
type SenderOptionFunc func(sender *sender)
// Add a transformer, which Sender uses while encoding a binding.Message to an amqp.Message
func WithTransformer(transformer binding.TransformerFactory) SenderOptionFunc {
return func(sender *sender) {
sender.transformers = append(sender.transformers, transformer)
}
}