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"` }