-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathoptions.go
More file actions
663 lines (591 loc) · 25 KB
/
Copy pathoptions.go
File metadata and controls
663 lines (591 loc) · 25 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
package centrifuge
import (
"time"
"github.com/centrifugal/protocol"
)
// PublishOption is a type to represent various Publish options.
type PublishOption func(*PublishOptions)
// WithHistory tells Broker to save message to history stream with provided size and ttl.
func WithHistory(size int, ttl time.Duration, metaTTL ...time.Duration) PublishOption {
return func(opts *PublishOptions) {
opts.HistorySize = size
opts.HistoryTTL = ttl
if len(metaTTL) > 0 {
opts.HistoryMetaTTL = metaTTL[0]
}
}
}
// WithIdempotencyKey tells Broker the idempotency key for the publication.
// See PublishOptions.IdempotencyKey.
func WithIdempotencyKey(key string) PublishOption {
return func(opts *PublishOptions) {
opts.IdempotencyKey = key
}
}
// WithKey sets a key for the publication. When set, the publication is associated
// with a specific key within the channel. This may enable per-key debouncing or
// channel level per-key batching. The key is delivered to subscribers in the Publication.
func WithKey(key string) PublishOption {
return func(opts *PublishOptions) {
opts.Key = key
}
}
// WithDelta tells Broker to use delta streaming.
func WithDelta(enabled bool) PublishOption {
return func(opts *PublishOptions) {
opts.UseDelta = enabled
}
}
// WithIdempotentResultTTL sets the time of expiration for results of idempotent publications.
// See PublishOptions.IdempotentResultTTL for more description and defaults.
func WithIdempotentResultTTL(ttl time.Duration) PublishOption {
return func(opts *PublishOptions) {
opts.IdempotentResultTTL = ttl
}
}
// WithClientInfo adds ClientInfo to Publication.
func WithClientInfo(info *ClientInfo) PublishOption {
return func(opts *PublishOptions) {
opts.ClientInfo = info
}
}
// WithTags allows setting Publication.Tags.
func WithTags(tags map[string]string) PublishOption {
return func(opts *PublishOptions) {
opts.Tags = tags
}
}
// WithVersion allows application to provide a tip for Centrifuge about
// internal application version of Publication. This is helpful to drop
// non-actual publications on Centrifuge Broker level. Publications may be
// non-actual in case of unordered publish calls from application side.
// In some cases application may want Centrifuge to avoid delivery of these
// publications.
// This is mostly useful for scenarios when channel publications contain the
// entire state, so skipping intermediary messages is safe and beneficial.
// This also means that Centrifuge history will contain the most recent Publication,
// so the recovery will return the proper state (and state should be eventually
// consistent in case of at least one delivery).
// This option must be used only with channels that have history enabled. Note,
// these version and versionEpoch are not used as Centrifuge channel stream position.
// Centrifuge still generates its own independent StreamPosition for each Publication
// in channel streams with history, but it additionally starts keeping version and
// versionEpoch provided here.
// If versionEpoch is an empty string, then Centrifuge does not look at it when comparing
// versions.
func WithVersion(version uint64, versionEpoch string) PublishOption {
return func(opts *PublishOptions) {
opts.Version = version
opts.VersionEpoch = versionEpoch
}
}
// SubscriptionType defines the type of subscription.
type SubscriptionType int32
const (
// SubscriptionTypeStream is a regular PUB/SUB subscription (default).
SubscriptionTypeStream SubscriptionType = 0
// SubscriptionTypeMap is a map subscription with keyed state.
SubscriptionTypeMap SubscriptionType = 1
// SubscriptionTypeMapClients is a client presence subscription on a map channel.
SubscriptionTypeMapClients SubscriptionType = 2
// SubscriptionTypeMapUsers is a user presence subscription on a map channel.
SubscriptionTypeMapUsers SubscriptionType = 3
// SubscriptionTypeSharedPoll is a shared poll subscription.
SubscriptionTypeSharedPoll SubscriptionType = 4
)
// IsMapPresence reports whether t is a map presence subscription type
// (SubscriptionTypeMapClients or SubscriptionTypeMapUsers).
func (t SubscriptionType) IsMapPresence() bool {
return t == SubscriptionTypeMapClients || t == SubscriptionTypeMapUsers
}
func (t SubscriptionType) String() string {
switch t {
case SubscriptionTypeStream:
return "stream"
case SubscriptionTypeMap:
return "map"
case SubscriptionTypeMapClients:
return "map_clients"
case SubscriptionTypeMapUsers:
return "map_users"
case SubscriptionTypeSharedPoll:
return "shared_poll"
default:
return "unknown"
}
}
// FilterNode is a filter expression tree for matching against key-value tags.
// Used for server-side publication filtering (ServerTagsFilter in SubscribeOptions).
type FilterNode = protocol.FilterNode
// SubscribeOptions define per-subscription options.
type SubscribeOptions struct {
// clientID to subscribe.
clientID string
// sessionID to subscribe.
sessionID string
// ExpireAt defines time in future when subscription should expire,
// zero value means no expiration.
ExpireAt int64
// ChannelInfo defines custom channel information, zero value means no channel information.
ChannelInfo []byte
// EmitPresence turns on participating in channel presence - i.e. client
// subscription will emit presence updates to PresenceManager and will be visible
// in a channel presence result.
EmitPresence bool
// EmitJoinLeave turns on emitting Join and Leave events from the subscribing client.
// See also PushJoinLeave if you want current client to receive join/leave messages.
EmitJoinLeave bool
// PushJoinLeave turns on receiving channel Join and Leave events by the client.
// Subscriptions which emit join/leave events should have EmitJoinLeave on.
PushJoinLeave bool
// When position is on client will additionally sync its position inside a stream
// to prevent publication loss. The loss can happen due to at most once guarantees
// of PUB/SUB model. Make sure you are enabling EnablePositioning in channels that
// maintain Publication history stream. When EnablePositioning is on Centrifuge will
// include StreamPosition information to subscribe response - for a client to be
// able to manually track its position inside a stream.
EnablePositioning bool
// EnableRecovery turns on automatic recovery for a channel. In this case
// client will try to recover missed messages upon resubscribe to a channel
// after reconnect to a server. This option also enables client position
// tracking inside a stream (i.e. enabling EnableRecovery will automatically
// enable EnablePositioning option) to prevent occasional publication loss.
// Make sure you are using EnableRecovery in channels that maintain Publication
// history stream.
EnableRecovery bool
// RecoveryMode is by default RecoveryModeStream, but can be also RecoveryModeCache.
RecoveryMode RecoveryMode
// Data to send to a client with Subscribe Push.
Data []byte
// RecoverSince will try to subscribe a client and recover from a certain StreamPosition.
RecoverSince *StreamPosition
// AutoCacheRecover, when set, makes Centrifuge initiate cache recovery for a subscription
// even if the client did not request it (i.e. without a recover flag/position in the
// subscribe request). It applies to both client-initiated and server-side subscriptions and
// requires EnableRecovery to be set.
//
// AutoCacheRecover only takes effect in cache recovery mode (RecoveryModeCache): there it
// delivers the latest publication on each (re)subscribe regardless of position, which is
// especially useful for unidirectional clients with server-side subscriptions that can't
// request recovery themselves, or to avoid requiring an empty "since" on the client.
//
// In stream recovery mode AutoCacheRecover is ignored: forcing recovery without a client
// position can't preserve continuity (there is no baseline to compare against), and the
// cache-style "deliver latest" semantics don't map onto a stream. To recover a stream
// subscription use the client recover flag/position, or SubscribeOptions.RecoverSince for a
// specific position; to deliver an initial backlog use SubscribeReply.Publications.
// AutoCacheRecover is also ignored for map subscriptions.
AutoCacheRecover bool
// HistoryMetaTTL allows to override default (set in Config.HistoryMetaTTL) history
// meta information expiration time.
HistoryMetaTTL time.Duration
// AllowedDeltaTypes is a whitelist of DeltaType subscribers can negotiate. At this point Centrifuge
// only supports DeltaTypeFossil. If zero value – clients won't be able to negotiate delta encoding
// within a channel and will receive full data in publications.
// Delta encoding is an EXPERIMENTAL feature and may be changed.
AllowedDeltaTypes []DeltaType
// Source is a way to mark the source of Subscription - i.e. where it comes from. May be useful
// for inspection of a connection during its lifetime.
Source uint8
// AllowChannelCompaction if true allows client to negotiate channel ID compaction –
// Centrifuge will replace channel names with shorter IDs in subscription pushes.
// If disabled, clients receive the full channel name in all pushes. Requires support
// in client SDK.
AllowChannelCompaction bool
// AllowTagsFilter if set to true allows client to use publication filter by tags. If not allowed
// and client provided a filter – the BadRequest error will be returned.
// Important note here, since channel permissions are managed on channel level, tags filtering
// must be used as a bandwidth optimization, not an access control mechanism.
AllowTagsFilter bool
// ServerTagsFilter is a server-controlled tags filter applied to publications before delivery.
// Unlike AllowTagsFilter (which enables client-side filtering), this filter is set by the server
// (via subscribe proxy or JWT) and cannot be overridden by the client. When both server and
// client filters are set, they are applied independently (AND semantics). ServerTagsFilter
// can not be used together with Delta Compression in subscription.
ServerTagsFilter *FilterNode
// Type defines the subscription type. Use SubscriptionTypeMap for map subscriptions.
// For regular subscriptions this can be left as zero value (SubscriptionTypeStream).
Type SubscriptionType
// MapClientPresenceChannel is the full channel name for client presence.
// When set, client presence will be published to this channel on subscribe.
// Empty string means no client presence publishing.
MapClientPresenceChannel string
// MapUserPresenceChannel is the full channel name for user presence.
// When set, user presence will be published to this channel on subscribe.
// Empty string means no user presence publishing.
MapUserPresenceChannel string
// MapRemoveClientOnUnsubscribe enables automatic cleanup of map state when the
// subscription ends – the key matching current client ID will be removed.
// This is useful for ephemeral state like cursor positions or temporary resources
// that should not persist after the client leaves.
MapRemoveClientOnUnsubscribe bool
// ClientPublishDebounceInterval when > 0, included in the subscribe result
// as publish_debounce (milliseconds). The SDK debounces client-initiated publishes
// to this channel locally.
ClientPublishDebounceInterval time.Duration
// labelFilter narrows the subscribe to a subset of the user's connections by
// matching against Client.Labels (the full map set via ConnectReply.Labels —
// NOT only the keys whitelisted in MetricsConfig.ClientLabels). A user with
// multiple connections may end up partially subscribed; non-matching
// connections are left untouched. Subscribe never removes an existing
// subscription from a non-matching connection. Combined with clientID and
// sessionID using AND semantics. A malformed filter causes Node.Subscribe
// to return an error. Nil means no label filtering. Set via WithSubscribeLabelFilter.
labelFilter *FilterNode
// allUsers changes the meaning of an empty userID passed to Node.Subscribe.
// By default an empty userID targets the anonymous-user bucket (connections
// established without authentication). When allUsers is true and userID is
// empty, Subscribe instead iterates every connection on every node — useful
// for fleet-wide ops combined with labelFilter (e.g. "subscribe all EU pro
// users to a new channel"). When userID is non-empty this option has no
// effect: the per-user path is always taken. Set via WithSubscribeAllUsers.
allUsers bool
}
// SubscribeOption is a type to represent various Subscribe options.
type SubscribeOption func(*SubscribeOptions)
// WithExpireAt allows setting ExpireAt field.
func WithExpireAt(expireAt int64) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.ExpireAt = expireAt
}
}
// WithChannelInfo ...
func WithChannelInfo(chanInfo []byte) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.ChannelInfo = chanInfo
}
}
// WithEmitPresence ...
func WithEmitPresence(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.EmitPresence = enabled
}
}
// WithEmitJoinLeave ...
func WithEmitJoinLeave(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.EmitJoinLeave = enabled
}
}
// WithPushJoinLeave ...
func WithPushJoinLeave(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.PushJoinLeave = enabled
}
}
// WithPositioning ...
func WithPositioning(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.EnablePositioning = enabled
}
}
// WithRecovery ...
func WithRecovery(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.EnableRecovery = enabled
}
}
type RecoveryMode uint8
const (
RecoveryModeStream RecoveryMode = 0
RecoveryModeCache RecoveryMode = 1
)
// WithRecoveryMode ...
func WithRecoveryMode(mode RecoveryMode) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.RecoveryMode = mode
}
}
// WithSubscribeClient allows setting client ID that should be subscribed.
// This option not used when Client.Subscribe called.
func WithSubscribeClient(clientID string) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.clientID = clientID
}
}
// WithSubscribeSession allows setting session ID that should be subscribed.
// This option not used when Client.Subscribe called.
func WithSubscribeSession(sessionID string) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.sessionID = sessionID
}
}
// WithSubscribeData allows setting custom data to send with subscribe push.
func WithSubscribeData(data []byte) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.Data = data
}
}
// WithRecoverSince allows setting SubscribeOptions.RecoverFrom.
func WithRecoverSince(since *StreamPosition) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.RecoverSince = since
}
}
// WithAutoCacheRecover allows setting SubscribeOptions.AutoCacheRecover. It makes Centrifuge
// initiate cache recovery for a subscription even if the client did not request it. See
// SubscribeOptions.AutoCacheRecover for details.
func WithAutoCacheRecover(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.AutoCacheRecover = enabled
}
}
// WithSubscribeSource allows setting SubscribeOptions.Source.
func WithSubscribeSource(source uint8) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.Source = source
}
}
// WithSubscribeHistoryMetaTTL allows setting SubscribeOptions.HistoryMetaTTL.
func WithSubscribeHistoryMetaTTL(metaTTL time.Duration) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.HistoryMetaTTL = metaTTL
}
}
// WithSubscribeLabelFilter restricts the subscribe to connections whose
// Client.Labels match the filter. See SubscribeOptions.LabelFilter for the
// detailed contract.
func WithSubscribeLabelFilter(f *FilterNode) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.labelFilter = f
}
}
// WithSubscribeAllUsers changes the meaning of an empty userID passed to
// Node.Subscribe from "anonymous bucket only" to "all users including
// anonymous." It is a no-op when userID is non-empty — the per-user path
// is always taken in that case. Typically combined with
// WithSubscribeLabelFilter to narrow the fleet-wide dispatch.
func WithSubscribeAllUsers(enabled bool) SubscribeOption {
return func(opts *SubscribeOptions) {
opts.allUsers = enabled
}
}
// RefreshOptions ...
type RefreshOptions struct {
// Expired can close connection with expired reason.
Expired bool
// ExpireAt defines time in future when subscription should expire,
// zero value means no expiration.
ExpireAt int64
// Info defines custom channel information, zero value means no channel information.
Info []byte
// clientID to refresh.
clientID string
// sessionID to refresh.
sessionID string
// labelFilter narrows the refresh to a subset of the user's connections by
// matching against Client.Labels (the full map set via ConnectReply.Labels —
// NOT only the keys whitelisted in MetricsConfig.ClientLabels). A user with
// multiple connections may end up partially refreshed. Combined with clientID
// and sessionID using AND semantics. A malformed filter causes Node.Refresh
// to return an error. Nil means no label filtering. Set via WithRefreshLabelFilter.
labelFilter *FilterNode
// allUsers changes the meaning of an empty userID passed to Node.Refresh.
// See SubscribeOptions.allUsers for the contract. Set via WithRefreshAllUsers.
allUsers bool
}
// RefreshOption is a type to represent various Refresh options.
type RefreshOption func(options *RefreshOptions)
// WithRefreshClient to limit refresh only for specified client ID.
func WithRefreshClient(clientID string) RefreshOption {
return func(opts *RefreshOptions) {
opts.clientID = clientID
}
}
// WithRefreshSession to limit refresh only for specified session ID.
func WithRefreshSession(sessionID string) RefreshOption {
return func(opts *RefreshOptions) {
opts.sessionID = sessionID
}
}
// WithRefreshExpired to set expired flag - connection will be closed with DisconnectExpired.
func WithRefreshExpired(expired bool) RefreshOption {
return func(opts *RefreshOptions) {
opts.Expired = expired
}
}
// WithRefreshExpireAt to set unix seconds in the future when connection should expire.
// Zero value means no expiration.
func WithRefreshExpireAt(expireAt int64) RefreshOption {
return func(opts *RefreshOptions) {
opts.ExpireAt = expireAt
}
}
// WithRefreshInfo to override connection info.
func WithRefreshInfo(info []byte) RefreshOption {
return func(opts *RefreshOptions) {
opts.Info = info
}
}
// WithRefreshLabelFilter restricts the refresh to connections whose
// Client.Labels match the filter. See RefreshOptions.LabelFilter for the
// detailed contract.
func WithRefreshLabelFilter(f *FilterNode) RefreshOption {
return func(opts *RefreshOptions) {
opts.labelFilter = f
}
}
// WithRefreshAllUsers changes the meaning of an empty userID passed to
// Node.Refresh from "anonymous bucket only" to "all users including
// anonymous." It is a no-op when userID is non-empty.
func WithRefreshAllUsers(enabled bool) RefreshOption {
return func(opts *RefreshOptions) {
opts.allUsers = enabled
}
}
// UnsubscribeOptions ...
type UnsubscribeOptions struct {
// clientID to unsubscribe.
clientID string
// sessionID to unsubscribe.
sessionID string
// custom unsubscribe object.
unsubscribe *Unsubscribe
// labelFilter narrows the unsubscribe to a subset of the user's connections
// by matching against Client.Labels (the full map set via ConnectReply.Labels
// — NOT only the keys whitelisted in MetricsConfig.ClientLabels). When the
// channel argument is empty (unsubscribe from all channels), the filter still
// applies and narrows which connections are affected. Combined with clientID
// and sessionID using AND semantics. A malformed filter causes
// Node.Unsubscribe to return an error. Nil means no label filtering.
// Set via WithUnsubscribeLabelFilter.
labelFilter *FilterNode
// allUsers changes the meaning of an empty userID passed to Node.Unsubscribe.
// See SubscribeOptions.allUsers for the contract. Set via WithUnsubscribeAllUsers.
allUsers bool
}
// UnsubscribeOption is a type to represent various Unsubscribe options.
type UnsubscribeOption func(options *UnsubscribeOptions)
// WithUnsubscribeClient allows setting client ID that should be unsubscribed.
// This option not used when Client.Unsubscribe called.
func WithUnsubscribeClient(clientID string) UnsubscribeOption {
return func(opts *UnsubscribeOptions) {
opts.clientID = clientID
}
}
// WithUnsubscribeSession allows setting session ID that should be unsubscribed.
// This option not used when Client.Unsubscribe called.
func WithUnsubscribeSession(sessionID string) UnsubscribeOption {
return func(opts *UnsubscribeOptions) {
opts.sessionID = sessionID
}
}
// WithCustomUnsubscribe allows setting custom Unsubscribe.
func WithCustomUnsubscribe(unsubscribe Unsubscribe) UnsubscribeOption {
return func(opts *UnsubscribeOptions) {
opts.unsubscribe = &unsubscribe
}
}
// WithUnsubscribeLabelFilter restricts the unsubscribe to connections whose
// Client.Labels match the filter. See UnsubscribeOptions.LabelFilter for the
// detailed contract.
func WithUnsubscribeLabelFilter(f *FilterNode) UnsubscribeOption {
return func(opts *UnsubscribeOptions) {
opts.labelFilter = f
}
}
// WithUnsubscribeAllUsers changes the meaning of an empty userID passed to
// Node.Unsubscribe from "anonymous bucket only" to "all users including
// anonymous." It is a no-op when userID is non-empty.
func WithUnsubscribeAllUsers(enabled bool) UnsubscribeOption {
return func(opts *UnsubscribeOptions) {
opts.allUsers = enabled
}
}
// DisconnectOptions define some fields to alter behaviour of Disconnect operation.
type DisconnectOptions struct {
// Disconnect represents custom disconnect to use.
// By default, DisconnectForceNoReconnect will be used.
Disconnect *Disconnect
// ClientWhitelist contains client IDs to keep.
ClientWhitelist []string
// clientID to disconnect.
clientID string
// sessionID to disconnect.
sessionID string
// labelFilter narrows the disconnect to a subset of the user's connections by
// matching against Client.Labels (the full map set via ConnectReply.Labels —
// NOT only the keys whitelisted in MetricsConfig.ClientLabels). Combined with
// ClientWhitelist, clientID and sessionID using AND semantics — a connection
// must clear every set check to be disconnected. A malformed filter causes
// Node.Disconnect to return an error. Nil means no label filtering.
// Set via WithDisconnectLabelFilter.
labelFilter *FilterNode
// allUsers changes the meaning of an empty userID passed to Node.Disconnect.
// See SubscribeOptions.allUsers for the contract. Set via WithDisconnectAllUsers.
allUsers bool
}
// DisconnectOption is a type to represent various Disconnect options.
type DisconnectOption func(options *DisconnectOptions)
// WithCustomDisconnect allows setting custom Disconnect.
func WithCustomDisconnect(disconnect Disconnect) DisconnectOption {
return func(opts *DisconnectOptions) {
opts.Disconnect = &disconnect
}
}
// WithDisconnectClient allows setting Client.
func WithDisconnectClient(clientID string) DisconnectOption {
return func(opts *DisconnectOptions) {
opts.clientID = clientID
}
}
// WithDisconnectSession allows setting session ID to disconnect.
func WithDisconnectSession(sessionID string) DisconnectOption {
return func(opts *DisconnectOptions) {
opts.sessionID = sessionID
}
}
// WithDisconnectClientWhitelist allows setting ClientWhitelist.
func WithDisconnectClientWhitelist(whitelist []string) DisconnectOption {
return func(opts *DisconnectOptions) {
opts.ClientWhitelist = whitelist
}
}
// WithDisconnectLabelFilter restricts the disconnect to connections whose
// Client.Labels match the filter. See DisconnectOptions.LabelFilter for the
// detailed contract.
func WithDisconnectLabelFilter(f *FilterNode) DisconnectOption {
return func(opts *DisconnectOptions) {
opts.labelFilter = f
}
}
// WithDisconnectAllUsers changes the meaning of an empty userID passed to
// Node.Disconnect from "anonymous bucket only" to "all users including
// anonymous." It is a no-op when userID is non-empty.
func WithDisconnectAllUsers(enabled bool) DisconnectOption {
return func(opts *DisconnectOptions) {
opts.allUsers = enabled
}
}
// HistoryOption is a type to represent various History options.
type HistoryOption func(options *HistoryOptions)
// NoLimit defines that limit should not be applied.
const NoLimit = -1
// WithLimit allows setting HistoryOptions.Limit.
func WithLimit(limit int) HistoryOption {
return func(opts *HistoryOptions) {
opts.Filter.Limit = limit
}
}
// WithSince allows setting HistoryOptions.Since option.
func WithSince(sp *StreamPosition) HistoryOption {
return func(opts *HistoryOptions) {
opts.Filter.Since = sp
}
}
// WithReverse allows setting HistoryOptions.Reverse option.
func WithReverse(reverse bool) HistoryOption {
return func(opts *HistoryOptions) {
opts.Filter.Reverse = reverse
}
}
func WithHistoryFilter(filter HistoryFilter) HistoryOption {
return func(opts *HistoryOptions) {
opts.Filter = filter
}
}
func WithHistoryMetaTTL(metaTTL time.Duration) HistoryOption {
return func(opts *HistoryOptions) {
opts.MetaTTL = metaTTL
}
}