JSON-RPC 2.0 client for Go
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2015-09-02 11:56:32 +02:00
cmd/pingflood Command to test and measure pipelining 2013-10-08 07:30:54 +02:00
common_test.go Procera dialect tests & fixes 2013-10-07 17:29:30 +02:00
doc.go Deprecate package 2015-01-05 12:00:28 +01:00
examples_test.go Comment clarification 2013-10-07 21:24:26 +02:00
jsonrpc.go Like I said, deprecated 2015-09-02 11:44:30 +02:00
jsonrpc_test.go Test coverage to 100% 2013-10-07 17:54:17 +02:00
LICENSE README & LICENSE 2013-10-07 17:32:35 +02:00
procera_dialect.go Procera dialect tests & fixes 2013-10-07 17:29:30 +02:00
procera_test.go Procera dialect tests & fixes 2013-10-07 17:29:30 +02:00
README.md Deprecated. 2015-09-02 11:56:32 +02:00
standard_dialect.go Initial 2013-10-07 12:34:45 +02:00
standard_test.go Races, errors and example 2013-10-07 17:18:35 +02:00

DEPRECATION WARNING This package is unmaintained and probably not what you're looking for.

jsonrpc

Package jsonrpc implements a standards compliant, asynchronous JSON-RPC client. The JSON-RPC 2.0 standard as specified in http://www.jsonrpc.org/specification is supported, while it is also possible to implement vendor specific dialects. The client is thread safe, i.e. request and notification functions can be called from any goroutine.

Documentation

http://godoc.org/github.com/calmh/jsonrpc

Example

// Connect to a remote JSON-RPC server

conn, err := net.Dial("tcp", "svr.example.com:3994")
if err != nil {
	panic(err)
}

// Set up a JSON-RPC channel on top of the socket, standard JSON-RPC 2.0
// dialect

rpc := jsonrpc.NewConnection(conn, jsonrpc.StandardDialect)

// Create two request functions, one for the method "hello" and one for the
// method "system.ping".

hello := rpc.Request("hello")
ping := rpc.Request("system.ping")

// Call the hello method with one string parameter.
// {"id": 0, "method": "hello", "params": ["world"], "jsonrpc": "2.0"}

helloRc, err := hello("world")
if err != nil {
	panic(err)
}

// Call the ping method with an empty parameter list. Note that we do not
// wait for the server to complete the hello request above before sending
// the ping request -- this is request pipelining.
// {"id": 1, "method": "ping", "params": [], "jsonrpc": "2.0"}

pingRc, err := ping()
if err != nil {
	panic(err)
}

// Await the response for the ping request and then the hello request. It
// does not matter in which order the server returned the responses.

var resp jsonrpc.Response
var ok bool
resp, ok = <-pingRc
if !ok {
	panic("read error reading response")
}
fmt.Printf("%v\n", resp)
resp, ok = <-helloRc
if !ok {
	panic("read error reading response")
}
fmt.Printf("%v\n", resp)

License

MIT