-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmessage.go
More file actions
49 lines (41 loc) · 1.5 KB
/
message.go
File metadata and controls
49 lines (41 loc) · 1.5 KB
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
package jsonrpc
import "encoding/json"
// JSON-RPC 2.0 message types. Version field is ommited for brevity.
// Request is a JSON-RPC request object.
type Request struct {
ID string `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
// Notification is a JSON-RPC notification object.
type Notification struct {
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
// Response is a JSON-RPC response object.
type Response struct {
ID string `json:"id"`
Result interface{} `json:"result,omitempty"`
Error *ResError `json:"error,omitempty"`
}
// ResError is a JSON-RPC response error object.
type ResError struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
// message is a JSON-RPC request, response, or notification message.
// This is used internally only to manage incoming messages.
// We don't need this for outgoing messages as we always know their specific types.
type message struct {
ID string `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"` // request params
Result json.RawMessage `json:"result,omitempty"` // response result
Error *resError `json:"error,omitempty"` // response error
}
type resError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}