-
Notifications
You must be signed in to change notification settings - Fork 17
/
transferconfig.go
47 lines (38 loc) · 1.13 KB
/
transferconfig.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
package datatransfer
type TransportOption func(chid ChannelID, transport Transport) error
type transferConfig struct {
eventsCb Subscriber
transportOptions []TransportOption
}
func (tc *transferConfig) EventsCb() Subscriber {
return tc.eventsCb
}
func (tc *transferConfig) TransportOptions() []TransportOption {
return tc.transportOptions
}
// TransferOption customizes a single transfer
type TransferOption func(*transferConfig)
// WithSubscriber dispatches only events for this specific channel transfer
func WithSubscriber(eventsCb Subscriber) TransferOption {
return func(tc *transferConfig) {
tc.eventsCb = eventsCb
}
}
func WithTransportOptions(transportOptions ...TransportOption) TransferOption {
return func(tc *transferConfig) {
tc.transportOptions = transportOptions
}
}
// TransferConfig accesses transfer properties
type TransferConfig interface {
EventsCb() Subscriber
TransportOptions() []TransportOption
}
// FromOptions builds a config from an options list
func FromOptions(options []TransferOption) TransferConfig {
tc := &transferConfig{}
for _, option := range options {
option(tc)
}
return tc
}