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
/
set_hook_query_builder.go
67 lines (57 loc) · 1.69 KB
/
set_hook_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
57
58
59
60
61
62
63
64
65
66
67
package t38c
import (
"context"
"strconv"
"strings"
)
// SetHookQueryBuilder struct
type SetHookQueryBuilder struct {
client tile38Client
name string
endpoints []string
cmd cmd
metas []Meta
expiration *int
}
func newSetHookQueryBuilder(client tile38Client, name, endpoint string, query cmd) SetHookQueryBuilder {
return SetHookQueryBuilder{
client: client,
name: name,
endpoints: []string{endpoint},
cmd: query,
}
}
func (query SetHookQueryBuilder) toCmd() cmd {
args := []string{query.name, strings.Join(query.endpoints, ",")}
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("SETHOOK", args...)
}
// Do cmd
func (query SetHookQueryBuilder) Do(ctx context.Context) error {
cmd := query.toCmd()
return query.client.jExecute(ctx, nil, cmd.Name, cmd.Args...)
}
// Endpoint appends new endpoint to the hook.
// Tile38 will try to send a message to the first endpoint.
// If the send is a failure then the second endpoint is tried, and so on.
func (query SetHookQueryBuilder) Endpoint(endpoint string) SetHookQueryBuilder {
query.endpoints = append(query.endpoints, endpoint)
return query
}
// Expiration set the specified expire time, in seconds.
func (query SetHookQueryBuilder) Expiration(seconds int) SetHookQueryBuilder {
query.expiration = &seconds
return query
}
// Meta ...
func (query SetHookQueryBuilder) Meta(name, value string) SetHookQueryBuilder {
query.metas = append(query.metas, Meta{name, value})
return query
}