From efbca43f27912ce5f5694fa4613a036fe938bf3f Mon Sep 17 00:00:00 2001 From: Alexey Date: Tue, 29 Jul 2025 11:26:26 +0300 Subject: [PATCH] make both Response and Error in one structure --- internal/server/rpc/definition.go | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/internal/server/rpc/definition.go b/internal/server/rpc/definition.go index c213fc8..68039f7 100644 --- a/internal/server/rpc/definition.go +++ b/internal/server/rpc/definition.go @@ -1,27 +1,20 @@ package rpc -type RPCRequest struct { - JSONRPC string `json:"jsonrpc"` - ID any `json:"id"` - Method string `json:"method"` - Params RPCRequestParams `json:"params"` -} +import "encoding/json" -type RPCRequestParams struct { - ContextVersion string `json:"context-version"` - Method map[string]any `json:"method-params"` +type RPCRequest struct { + JSONRPC string `json:"jsonrpc"` + ID *json.RawMessage `json:"id,omitempty"` + Method string `json:"method"` + Params any `json:"params,omitempty"` + ContextVersion string `json:"context-version,omitempty"` } type RPCResponse struct { - JSONRPC string `json:"jsonrpc"` - ID any `json:"id"` - Result any `json:"result"` -} - -type RPCError struct { - JSONRPC string `json:"jsonrpc"` - ID any `json:"id"` - Error any `json:"error"` + JSONRPC string `json:"jsonrpc"` + ID *json.RawMessage `json:"id"` + Result any `json:"result,omitempty"` + Error any `json:"error,omitempty"` } const (