From 889581c37e0bbf9945f4134aa49534f9f9b47982 Mon Sep 17 00:00:00 2001 From: Marin Date: Thu, 7 Nov 2019 16:40:27 +0100 Subject: [PATCH] Fix encoding request when params are nil --- json/client.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/json/client.go b/json/client.go index 3dadd03..bf27927 100644 --- a/json/client.go +++ b/json/client.go @@ -22,7 +22,7 @@ type clientRequest struct { // A String containing the name of the method to be invoked. Method string `json:"method"` // Object to pass as request parameter to the method. - Params [1]interface{} `json:"params"` + Params []interface{} `json:"params,omitempty"` // The request id. This can be of any type. It is used to match the // response with the request that it is replying to. Id uint64 `json:"id"` @@ -39,9 +39,12 @@ type clientResponse struct { func EncodeClientRequest(method string, args interface{}) ([]byte, error) { c := &clientRequest{ Method: method, - Params: [1]interface{}{args}, Id: uint64(rand.Int63()), } + if args != nil { + c.Params = []interface{}{args} + } + return json.Marshal(c) }