forked from forbole/juno
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtypes.go
More file actions
41 lines (34 loc) · 874 Bytes
/
types.go
File metadata and controls
41 lines (34 loc) · 874 Bytes
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
package jsonrpc2
import (
"encoding/json"
"fmt"
)
const ProtocolVersion = "2.0"
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
func NewRequest(id any, method string, params json.RawMessage) Request {
return Request{
JSONRPC: ProtocolVersion,
ID: id,
Method: method,
Params: params,
}
}
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID any `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
func (e Error) Error() string {
return fmt.Sprintf("%s (%d)", e.Message, e.Code)
}