forked from shadowspore/t38c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_channel_query_builder.go
56 lines (47 loc) · 1.28 KB
/
set_channel_query_builder.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
package t38c
import (
"context"
"strconv"
)
// SetChannelQueryBuilder struct
type SetChannelQueryBuilder struct {
client tile38Client
name string
cmd cmd
metas []Meta
expiration *int
}
func newSetChannelQueryBuilder(client tile38Client, name string, query cmd) SetChannelQueryBuilder {
return SetChannelQueryBuilder{
client: client,
name: name,
cmd: query,
}
}
func (query SetChannelQueryBuilder) toCmd() cmd {
args := []string{query.name}
for _, meta := range query.metas {
args = append(args, "META", meta.Name, meta.Value)
}
if query.expiration != nil {
args = append(args, "EX", strconv.Itoa(*query.expiration))
}
args = append(args, query.cmd.Name)
args = append(args, query.cmd.Args...)
return newCmd("SETCHAN", args...)
}
// Do cmd
func (query SetChannelQueryBuilder) Do(ctx context.Context) error {
cmd := query.toCmd()
return query.client.jExecute(ctx, nil, cmd.Name, cmd.Args...)
}
// Expiration set the specified expire time, in seconds.
func (query SetChannelQueryBuilder) Expiration(seconds int) SetChannelQueryBuilder {
query.expiration = &seconds
return query
}
// Meta ...
func (query SetChannelQueryBuilder) Meta(name, value string) SetChannelQueryBuilder {
query.metas = append(query.metas, Meta{name, value})
return query
}