I tried to send a request to a RPC interface, but the interface doesn't need params. It means the params field should be "params":[]
, but when I use json.EncodeClientRequest(method string, args interface{})
, the value of params is always "params":[{}]
or "params":[null]
. So it always causes the error: map[code:-32602 message:Invalid method parameters]
. How could I set a null value for params. Next is my request struct:
// request struct
type JsonRpcReq struct {
Id uint32 `json:"id"`
Url string `json:"url"`
Method string `json:"method"`
Params *interface{} `json:"params"`
JsonRpc string `json:"jsonrpc"`
}
The error of sentence is:
// request method
func (r *JsonRpcReq) Send() (interface{}, error) {
message, err := json.EncodeClientRequest(r.Method, r.Params)
fmt.Println(string(message))
if err != nil {
return nil, err
}
...
}
The request sentence is:
req := NewJsonRpcReq("http://finance.test.cppp.com/rpc/healthCheck", "status", nil)
The NewJsonRpcReq
method is:
func NewJsonRpcReq(url, method string, params *interface{}) *JsonRpcReq {
return &JsonRpcReq{Id: 0, Url: url, Method: method, Params: params, JsonRpc: "2.0"}
}