-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsonrpc.go
43 lines (37 loc) · 936 Bytes
/
jsonrpc.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
package jsonrpc
import "encoding/json"
const (
SupportedVersion = "2.0"
InvalidRequest = -32600
MethodNotFound = -32601
InvalidParams = -32602
InternalError = -32603
ParseError = -32700
)
var (
InternalErrorTemplate = `{"jsonrpc":"2.0","error":{"code":-32603,"message":"%s"},"id": null}`
DefaultInternalError = []byte(`{"jsonrpc":"2.0","error":{"code":-32603,"message":"Internal Error"},"id": null}`)
)
type (
Proxy interface {
Encode(Response)
}
// Method for JSONRPC requests
Method interface {
Process(json.RawMessage) (json.Marshaler, *Error)
}
// Handler for JSONRPC notifications
Handler interface {
Process(json.RawMessage)
}
// Callback for JSONRPC response callback
Callback interface {
Process(Response)
}
)
// Dispatcher holds RPC call routing implementation
type Dispatcher interface {
DispatchResponse(Response)
DispatchNotification(Request)
DispatchRequest(Request, Responder)
}