-
Notifications
You must be signed in to change notification settings - Fork 217
/
options.go
72 lines (64 loc) · 1.98 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package client
import (
"fmt"
)
// Option is the function signature required to be considered an client.Option.
type Option func(*ceClient) error
// WithEventDefaulter adds an event defaulter to the end of the defaulter chain.
func WithEventDefaulter(fn EventDefaulter) Option {
return func(c *ceClient) error {
if fn == nil {
return fmt.Errorf("client option was given an nil event defaulter")
}
c.eventDefaulterFns = append(c.eventDefaulterFns, fn)
return nil
}
}
// WithUUIDs adds DefaultIDToUUIDIfNotSet event defaulter to the end of the
// defaulter chain.
func WithUUIDs() Option {
return func(c *ceClient) error {
c.eventDefaulterFns = append(c.eventDefaulterFns, DefaultIDToUUIDIfNotSet)
return nil
}
}
// WithDataContentType adds the resulting defaulter from
// NewDefaultDataContentTypeIfNotSet event defaulter to the end of the
// defaulter chain.
func WithDataContentType(contentType string) Option {
return func(c *ceClient) error {
c.eventDefaulterFns = append(c.eventDefaulterFns, NewDefaultDataContentTypeIfNotSet(contentType))
return nil
}
}
// WithTimeNow adds DefaultTimeToNowIfNotSet event defaulter to the end of the
// defaulter chain.
func WithTimeNow() Option {
return func(c *ceClient) error {
c.eventDefaulterFns = append(c.eventDefaulterFns, DefaultTimeToNowIfNotSet)
return nil
}
}
// WithConverterFn defines the function the transport will use to delegate
// conversion of non-decodable messages.
func WithConverterFn(fn ConvertFn) Option {
return func(c *ceClient) error {
if fn == nil {
return fmt.Errorf("client option was given an nil message converter")
}
if c.transport.HasConverter() {
return fmt.Errorf("transport converter already set")
}
c.convertFn = fn
c.transport.SetConverter(c)
return nil
}
}
// WithoutTracePropagation disables automatic trace propagation via
// the distributed tracing extension.
func WithoutTracePropagation() Option {
return func(c *ceClient) error {
c.disableTracePropagation = true
return nil
}
}