@@ -58,21 +58,34 @@ func (id *ID) UnmarshalJSON(data []byte) error {
58
58
var _ json.Marshaler = (* ID )(nil )
59
59
var _ json.Unmarshaler = (* ID )(nil )
60
60
61
- // Request is a request message to describe a request between the client and the server.
61
+ // Request represents a rpc call by sending a request object to a Server.
62
+ // This is a request message to describe a request between the client and the server.
62
63
//
63
64
// Every processed request must send a response back to the sender of the request.
64
65
type Request struct {
65
- // JSONRPC is a general message as defined by JSON-RPC.
66
+ // JSONRPC is a string specifying the version of the JSON-RPC protocol.
67
+ //
68
+ // MUST be exactly "2.0".
66
69
JSONRPC string `json:"jsonrpc"`
67
70
68
- // The request id .
69
- ID * ID `json:"id"`
70
-
71
- // The method to be invoked .
71
+ // Method is a string containing the name of the method to be invoked .
72
+ //
73
+ // Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved
74
+ // for rpc-internal methods and extensions and MUST NOT be used for anything else .
72
75
Method string `json:"method"`
73
76
74
- // The method's params.
77
+ // Params is a string containing the name of the method to be invoked.
78
+ //
79
+ // Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved
80
+ // for rpc-internal methods and extensions and MUST NOT be used for anything else.
75
81
Params * json.RawMessage `json:"params,omitempty"`
82
+
83
+ // ID is an identifier established by the Client that MUST contain a String, Number, or NULL value if included.
84
+ //
85
+ // If it is not included it is assumed to be a notification.
86
+ //
87
+ // The value SHOULD normally not be Null and Numbers SHOULD NOT contain fractional parts.
88
+ ID * ID `json:"id"`
76
89
}
77
90
78
91
// IsNotify returns true if this request is a notification.
@@ -81,57 +94,70 @@ func (r *Request) IsNotify() bool {
81
94
}
82
95
83
96
// Response is a response ressage sent as a result of a request.
97
+ // When a rpc call is made, the Server MUST reply with a Response, except for in the case of Notifications.
84
98
//
85
99
// If a request doesn't provide a result value the receiver of a request still needs to return a response message to
86
100
// conform to the JSON RPC specification.
87
101
// The result property of the ResponseMessage should be set to null in this case to signal a successful request.
88
102
type Response struct {
89
- // JSONRPC is a general message as defined by JSON-RPC.
103
+ // JSONRPC is a string specifying the version of the JSON-RPC protocol.
104
+ //
105
+ // MUST be exactly "2.0".
90
106
JSONRPC string `json:"jsonrpc"`
91
107
92
- // The request id.
93
- ID * ID `json:"id"`
108
+ // Result is the result of a request.
109
+ //
110
+ // This member is REQUIRED on success.
111
+ // This member MUST NOT exist if there was an error invoking the method.
112
+ //
113
+ // The value of this member is determined by the method invoked on the Server.
114
+ Result * json.RawMessage `json:"result,omitempty"`
94
115
95
- // The error object in case a request fails.
116
+ // Error is the object in case a request fails.
117
+ //
118
+ // This member is REQUIRED on error.
119
+ // This member MUST NOT exist if there was no error triggered during invocation.
120
+ //
121
+ // The value for this member MUST be an Object.
96
122
Error * Error `json:"error,omitempty"`
97
123
98
- // The result of a request. This member is REQUIRED on success.
99
- // This member MUST NOT exist if there was an error invoking the method.
100
- Result * json.RawMessage `json:"result,omitempty"`
124
+ // ID is the request id.
125
+ //
126
+ // This member is REQUIRED.
127
+ // It MUST be the same as the value of the id member in the Request Object.
128
+ //
129
+ // If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request), it MUST be Null.
130
+ ID * ID `json:"id"`
101
131
}
102
132
103
133
// Combined represents a all the fields of both Request and Response.
104
134
type Combined struct {
105
- // JSONRPC is a general message as defined by JSON-RPC.
106
- JSONRPC string `json:"jsonrpc"`
107
-
108
- // The request id.
109
- ID * ID `json:"id,omitempty"`
110
-
111
- // The method to be invoked.
112
- Method string `json:"method"`
113
-
114
- // The method's params.
115
- Params * json.RawMessage `json:"params,omitempty"`
116
-
117
- // The error object in case a request fails.
118
- Error * Error `json:"error,omitempty"`
119
-
120
- // The result of a request. This member is REQUIRED on success.
121
- // This member MUST NOT exist if there was an error invoking the method.
122
- Result * json.RawMessage `json:"result,omitempty"`
135
+ JSONRPC string `json:"jsonrpc"`
136
+ Method string `json:"method"`
137
+ Params * json.RawMessage `json:"params,omitempty"`
138
+ Result * json.RawMessage `json:"result,omitempty"`
139
+ Error * Error `json:"error,omitempty"`
140
+ ID * ID `json:"id,omitempty"`
123
141
}
124
142
125
143
// NotificationMessage is a notification message.
126
144
//
127
145
// A processed notification message must not send a response back. They work like events.
128
146
type NotificationMessage struct {
129
- // JSONRPC is a general message as defined by JSON-RPC.
147
+ // JSONRPC is a string specifying the version of the JSON-RPC protocol.
148
+ //
149
+ // MUST be exactly "2.0".
130
150
JSONRPC string `json:"jsonrpc"`
131
151
132
- // Method is the method to be invoked.
152
+ // Method is a string containing the name of the method to be invoked.
153
+ //
154
+ // Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved
155
+ // for rpc-internal methods and extensions and MUST NOT be used for anything else.
133
156
Method string `json:"method"`
134
157
135
- // Params is the notification's params.
158
+ // Params is a string containing the name of the method to be invoked.
159
+ //
160
+ // Method names that begin with the word rpc followed by a period character (U+002E or ASCII 46) are reserved
161
+ // for rpc-internal methods and extensions and MUST NOT be used for anything else.
136
162
Params * json.RawMessage `json:"params,omitempty"`
137
163
}
0 commit comments