JSON RPC Client Go
Question: I have a python server serving response through JSON-RPC. Here is a sample
response from the server.

    
    
    '{"jsonrpc": "2.0", "result": "Peer 1: local 10.10.0.2  remote 10.10.0.1  state CONNECT\\nPeer 2: local 10.10.0.18  remote 10.10.0.17  state ESTABLISHED\\nPeer 3: local 10.10.0.10  remote 10.10.0.9  state ESTABLISHED", "id": "839732f9-cf36-46ff-8b9b-6120250d9ce5"}'
    

Here is the request I need to send to the server:

    
    
    '{"method":"echo","jsonrpc":"2.0","params":["test_params"],"id":"839732f9-cf36-46ff-8b9b-6120250d9ce5"}'
    

Here is my client with go language:

    
    
    package main
    
    import (
        "fmt"
        "log"
        "net"
        "net/rpc/jsonrpc"
    )
    type Args struct {
        jsonrpc, id string
    }
    
    func main() {
        conn, err := net.Dial("tcp", "11.21.22.221:8080")
        if err != nil {
            panic(err)
        }
        defer conn.Close()
    
        args := Args{"2.0", "d87198f0-af92-49f8-9a7d-ab8bed5c4d17"}
        var reply string
    
        c := jsonrpc.NewClient(conn)
    
        err = c.Call("echo", args, &reply)
        if err != nil {
            log.Fatal("error:", err)
        }
        fmt.Printf("Response: %d", reply)
    }
    

But, when I run this client, it is not sending anything in the params. Instead
it is sending empty params like this:

    
    
    '{"method":"echo","params":[{}],"id":0}\n
    

Can somebody help me telling what mistake I am making? I am a newbie to go
language.

Thanks.


Answer: I don't think what you are doing is possible using the client as provided by
go because the private `clientRequest` struct is currently defined as:

    
    
        type clientRequest struct {
            Method string         `json:"method"`
            Params [1]interface{} `json:"params"`
            Id     uint64         `json:"id"`
        }
    

What you pass into `Call` as `args` is stuck into `Params` and note how there
is no "Version `json:"jsonrpc"`" inside of that struct.

AFAICT (which may be wrong, this is my first time reading through this code)
you would need to implement your own
[ClientCodec](http://golang.org/pkg/net/rpc/#ClientCodec). You could probably
get away with copying most (all) of the parts out of the stdlib and add the
field to the `clientRequest` above. ;-)

