This repository has been archived by the owner on Dec 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
channels.go
50 lines (40 loc) · 1.7 KB
/
channels.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
package t38c
import "context"
// Channels struct
type Channels struct {
client tile38Client
}
// Chans returns all Channels matching pattern.
func (ch *Channels) Chans(ctx context.Context, pattern string) ([]Chan, error) {
var resp struct {
Chans []Chan `json:"chans"`
}
err := ch.client.jExecute(ctx, &resp, "CHANS", pattern)
if err != nil {
return nil, err
}
return resp.Chans, nil
}
// DelChan remove a specified channel.
func (ch *Channels) DelChan(ctx context.Context, name string) error {
return ch.client.jExecute(ctx, nil, "DELCHAN", name)
}
// PDelChan removes all Channels that match the specified pattern.
func (ch *Channels) PDelChan(ctx context.Context, pattern string) error {
return ch.client.jExecute(ctx, nil, "PDELCHAN", pattern)
}
// PSubscribe subscribes the client to the given patterns.
func (ch *Channels) PSubscribe(ctx context.Context, handler EventHandler, pattern string) error {
return ch.client.ExecuteStream(ctx, rawEventHandler(handler), "PSUBSCRIBE", pattern)
}
// SetChan creates a Pub/Sub channel which points to a geofenced search.
// If a channel is already associated to that name, it’ll be overwritten.
// Once the channel is created a client can then listen for events on that channel with SUBSCRIBE or PSUBSCRIBE.
// If expiration less than 0, it will be ignored
func (ch *Channels) SetChan(name string, query GeofenceQueryBuilder) SetChannelQueryBuilder {
return newSetChannelQueryBuilder(ch.client, name, query.toCmd())
}
// Subscribe subscribes the client to the specified Channels.
func (ch *Channels) Subscribe(ctx context.Context, handler EventHandler, Channels ...string) error {
return ch.client.ExecuteStream(ctx, rawEventHandler(handler), "SUBSCRIBE", Channels...)
}