forked from struckchure/gv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrpc.go
More file actions
47 lines (37 loc) · 1.06 KB
/
rpc.go
File metadata and controls
47 lines (37 loc) · 1.06 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
// Based on JSON-RPC 2.0 (https://www.jsonrpc.org/specification)
package gv
type RpcMethod struct {
Name string
Handler func(RpcRequest) RpcResponse
}
type RpcRequest struct {
Jsonrpc string `json:"jsonrpc"`
Method string `json:"method"`
Params any `json:"params"`
Id string `json:"id"`
}
type RpcErrorCode int
const (
RpcErrorCodeParseError RpcErrorCode = -32700
RpcErrorCodeInvalidRequest RpcErrorCode = -32600
RpcErrorCodeMethodNotFound RpcErrorCode = -32601
RpcErrorCodeInvalidParams RpcErrorCode = -32602
RpcErrorCodeInternalError RpcErrorCode = -32603
RpcErrorCodeServerError RpcErrorCode = -32000
)
type RpcError struct {
Code RpcErrorCode `json:"code"`
Message string `json:"message"`
Data any `json:"data"`
}
type RpcResponse struct {
Jsonrpc string `json:"jsonrpc"`
Result *any `json:"result,omitempty"`
Error *RpcError `json:"error,omitempty"`
Id string `json:"id"`
}
type RpcServer struct{}
func (r *RpcServer) Handle() {}
func NewRpcServer() *RpcServer {
return &RpcServer{}
}