Debian Codegraph @

options.go

raw
1 package centrifuge
2
3 import "time"
4
5 // PublishOption is a type to represent various Publish options.
6 type PublishOption func(*PublishOptions)
7
8 // WithHistory tells Broker to save message to history stream with provided size and ttl.
9 func WithHistory(size int, ttl time.Duration) PublishOption {
10 return func(opts *PublishOptions) {
11 opts.HistorySize = size
12 opts.HistoryTTL = ttl
13 }
14 }
15
16 // WithClientInfo adds ClientInfo to Publication.
17 func WithClientInfo(info *ClientInfo) PublishOption {
18 return func(opts *PublishOptions) {
19 opts.ClientInfo = info
20 }
21 }
22
23 // SubscribeOptions define per-subscription options.
24 type SubscribeOptions struct {
25 // ExpireAt defines time in future when subscription should expire,
26 // zero value means no expiration.
27 ExpireAt int64
28 // ChannelInfo defines custom channel information, zero value means no channel information.
29 ChannelInfo []byte
30 // Presence turns on participating in channel presence.
31 Presence bool
32 // JoinLeave enables sending Join and Leave messages for this client in channel.
33 JoinLeave bool
34 // When position is on client will additionally sync its position inside
35 // a stream to prevent message loss. Make sure you are enabling Position in channels
36 // that maintain Publication history stream. When Position is on Centrifuge will
37 // include StreamPosition information to subscribe response - for a client to be able
38 // to manually track its position inside a stream.
39 Position bool
40 // Recover turns on recovery option for a channel. In this case client will try to
41 // recover missed messages automatically upon resubscribe to a channel after reconnect
42 // to a server. This option also enables client position tracking inside a stream
43 // (like Position option) to prevent occasional message loss. Make sure you are using
44 // Recover in channels that maintain Publication history stream.
45 Recover bool
46 }
47
48 // UnsubscribeOptions define some fields to alter behaviour of Unsubscribe operation.
49 type UnsubscribeOptions struct {
50 // Resubscribe allows to set resubscribe protocol flag.
51 Resubscribe bool
52 }
53
54 // UnsubscribeOption is a type to represent various Unsubscribe options.
55 type UnsubscribeOption func(*UnsubscribeOptions)
56
57 // WithResubscribe allows to set Resubscribe flag to true.
58 func WithResubscribe(resubscribe bool) UnsubscribeOption {
59 return func(opts *UnsubscribeOptions) {
60 opts.Resubscribe = resubscribe
61 }
62 }
63
64 // DisconnectOptions define some fields to alter behaviour of Disconnect operation.
65 type DisconnectOptions struct {
66 // Disconnect represents custom disconnect to use.
67 // By default DisconnectForceNoReconnect will be used.
68 Disconnect *Disconnect
69 // ClientWhitelist contains client IDs to keep.
70 ClientWhitelist []string
71 }
72
73 // DisconnectOption is a type to represent various Disconnect options.
74 type DisconnectOption func(options *DisconnectOptions)
75
76 // WithDisconnect allows to set custom Disconnect.
77 func WithDisconnect(disconnect *Disconnect) DisconnectOption {
78 return func(opts *DisconnectOptions) {
79 opts.Disconnect = disconnect
80 }
81 }
82
83 // WithClientWhitelist allows to set ClientWhitelist.
84 func WithClientWhitelist(whitelist []string) DisconnectOption {
85 return func(opts *DisconnectOptions) {
86 opts.ClientWhitelist = whitelist
87 }
88 }
89
90 // HistoryOptions define some fields to alter History method behaviour.
91 type HistoryOptions struct {
92 // Since used to extract publications from stream since provided StreamPosition.
93 Since *StreamPosition
94 // Limit number of publications to return.
95 // -1 means no limit - i.e. return all publications currently in stream.
96 // 0 means that caller only interested in current stream top position so
97 // Broker should not return any publications in result.
98 // Positive integer does what it should.
99 Limit int
100 }
101
102 // HistoryOption is a type to represent various History options.
103 type HistoryOption func(options *HistoryOptions)
104
105 // NoLimit defines that limit should not be applied.
106 const NoLimit = -1
107
108 // WithLimit allows to set limit.
109 func WithLimit(limit int) HistoryOption {
110 return func(opts *HistoryOptions) {
111 opts.Limit = limit
112 }
113 }
114
115 // Since allows to set Since option.
116 func Since(sp *StreamPosition) HistoryOption {
117 return func(opts *HistoryOptions) {
118 opts.Since = sp
119 }
120 }