-
Notifications
You must be signed in to change notification settings - Fork 4
/
messages.go
177 lines (154 loc) · 3.72 KB
/
messages.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
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
package proxy
import (
"time"
document "github.com/Brickchain/go-document.v2"
uuid "github.com/satori/go.uuid"
)
const SchemaBase = "https://proxy.brickchain.com/v1"
type HttpRequest struct {
document.Base
URL string `json:"url"`
Query string `json:"query,omitempty"`
Headers map[string]string `json:"headers"`
Method string `json:"method"`
Body string `json:"body"`
}
func NewHttpRequest(url string) *HttpRequest {
return &HttpRequest{
Base: document.Base{
ID: uuid.Must(uuid.NewV4()).String(),
Type: SchemaBase + "/http-request.json",
Timestamp: time.Now().UTC(),
},
URL: url,
}
}
type HttpResponse struct {
document.Base
Headers map[string]string `json:"headers"`
ContentType string `json:"contentType"`
Status int `json:"status"`
Body string `json:"body"`
}
func NewHttpResponse(id string, status int) *HttpResponse {
return &HttpResponse{
Base: document.Base{
ID: id,
Type: SchemaBase + "/http-response.json",
Timestamp: time.Now().UTC(),
},
Status: status,
}
}
type RegistrationRequest struct {
document.Base
MandateToken string `json:"mandateToken"`
Session string `json:"session,omitempty"`
}
func NewRegistrationRequest(mandateToken string) *RegistrationRequest {
return &RegistrationRequest{
Base: document.Base{
ID: uuid.Must(uuid.NewV4()).String(),
Type: SchemaBase + "/registration-request.json",
Timestamp: time.Now().UTC(),
},
MandateToken: mandateToken,
}
}
type RegistrationResponse struct {
document.Base
KeyID string `json:"keyID"`
Hostname string `json:"hostname,omitempty"`
}
func NewRegistrationResponse(id string, keyID string) *RegistrationResponse {
return &RegistrationResponse{
Base: document.Base{
ID: id,
Type: SchemaBase + "/registration-response.json",
Timestamp: time.Now().UTC(),
},
KeyID: keyID,
}
}
type Ping struct {
document.Base
}
func NewPing() *Ping {
return &Ping{
Base: document.Base{
ID: uuid.Must(uuid.NewV4()).String(),
Type: SchemaBase + "/ping.json",
Timestamp: time.Now().UTC(),
},
}
}
type WSRequest struct {
document.Base
URL string `json:"url"`
Query string `json:"query,omitempty"`
Headers map[string]string `json:"headers"`
}
func NewWSRequest(url string) *WSRequest {
return &WSRequest{
Base: document.Base{
ID: uuid.Must(uuid.NewV4()).String(),
Type: SchemaBase + "/ws-request.json",
Timestamp: time.Now().UTC(),
},
URL: url,
Headers: make(map[string]string),
}
}
type WSResponse struct {
document.Base
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
}
func NewWSResponse(id string, ok bool) *WSResponse {
return &WSResponse{
Base: document.Base{
ID: id,
Type: SchemaBase + "/ws-response.json",
Timestamp: time.Now().UTC(),
},
OK: ok,
}
}
type WSMessage struct {
document.Base
MessageType int `json:"messageType"`
Body string `json:"body"`
}
func NewWSMessage(id string) *WSMessage {
return &WSMessage{
Base: document.Base{
ID: id,
Type: SchemaBase + "/ws-message.json",
Timestamp: time.Now().UTC(),
},
}
}
type WSTeardown struct {
document.Base
}
func NewWSTeardown(id string) *WSTeardown {
return &WSTeardown{
Base: document.Base{
ID: id,
Type: SchemaBase + "/ws-teardown.json",
Timestamp: time.Now().UTC(),
},
}
}
type Disconnect struct {
document.Base
}
func NewDisconnect() *Disconnect {
return &Disconnect{
Base: document.Base{
ID: uuid.Must(uuid.NewV4()).String(),
Type: SchemaBase + "/disconnect.json",
Timestamp: time.Now().UTC(),
},
}
}