-
Notifications
You must be signed in to change notification settings - Fork 47
/
requests.go
84 lines (70 loc) · 2.06 KB
/
requests.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package signalflow
import (
"encoding/json"
"time"
)
type AuthType string
func (at AuthType) MarshalJSON() ([]byte, error) {
return []byte(`"authenticate"`), nil
}
type AuthRequest struct {
Type AuthType `json:"type"`
// The Auth token for the org
Token string `json:"token"`
UserAgent string `json:"userAgent,omitempty"`
}
type ExecuteType string
func (ExecuteType) MarshalJSON() ([]byte, error) {
return []byte(`"execute"`), nil
}
type ExecuteRequest struct {
Type ExecuteType `json:"type"`
Program string `json:"program"`
Channel string `json:"channel"`
Start time.Time `json:"-"`
Stop time.Time `json:"-"`
Resolution time.Duration `json:"-"`
MaxDelay time.Duration `json:"-"`
StartMs int64 `json:"start"`
StopMs int64 `json:"stop"`
ResolutionMs int64 `json:"resolution"`
MaxDelayMs int64 `json:"maxDelay"`
Immediate bool `json:"immediate"`
Timezone string `json:"timezone"`
}
// MarshalJSON does some assignments to allow using more native Go types for
// time/duration.
func (er ExecuteRequest) MarshalJSON() ([]byte, error) {
if !er.Start.IsZero() {
er.StartMs = er.Start.UnixNano() / int64(time.Millisecond)
}
if !er.Stop.IsZero() {
er.StopMs = er.Stop.UnixNano() / int64(time.Millisecond)
}
if er.Resolution != 0 {
er.ResolutionMs = er.Resolution.Nanoseconds() / int64(time.Millisecond)
}
if er.MaxDelay != 0 {
er.MaxDelayMs = er.MaxDelay.Nanoseconds() / int64(time.Millisecond)
}
type alias ExecuteRequest
return json.Marshal(alias(er))
}
type DetachType string
func (DetachType) MarshalJSON() ([]byte, error) {
return []byte(`"detach"`), nil
}
type DetachRequest struct {
Type DetachType `json:"type"`
Channel string `json:"channel"`
Reason string `json:"reason"`
}
type StopType string
func (StopType) MarshalJSON() ([]byte, error) {
return []byte(`"stop"`), nil
}
type StopRequest struct {
Type StopType `json:"type"`
Handle string `json:"handle"`
Reason string `json:"reason"`
}