Implement RPC
This commit is contained in:
parent
9699582d72
commit
496d5f412f
6 changed files with 289 additions and 0 deletions
36
rpc/types.go
Normal file
36
rpc/types.go
Normal file
|
@ -0,0 +1,36 @@
|
|||
package rpc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type server struct {
|
||||
methods map[string]func(context.Context, Request) (any, error)
|
||||
requestMutex sync.Mutex
|
||||
requests map[string]chan *Response
|
||||
}
|
||||
|
||||
type Message struct {
|
||||
ID string `json:"id"`
|
||||
Method *string `json:"method,omitempty"`
|
||||
}
|
||||
|
||||
type Request struct {
|
||||
Method string `json:"method"`
|
||||
Params *json.RawMessage `json:"params,omitempty"`
|
||||
ID string `json:"id"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
ID string `json:"id"`
|
||||
Result *json.RawMessage `json:"result,omitempty"`
|
||||
Error *Error `json:"error,omitempty"`
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Code int64 `json:"code"`
|
||||
Message string `json:"message"`
|
||||
Data *json.RawMessage `json:"data,omitempty"`
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue