jsonrpc

package module
v0.0.0-...-85c8292 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 6, 2015 License: BSD-3-Clause Imports: 3 Imported by: 0

README

jsonrpc

jsonrpc is a wrapper around the standard net/rpc/jsonrpc package, providing support on the server side for naming conventions other than Service.Method.

I needed this in order to work with a JSON-RPC server implemented using something other than Go, which is using method names like "list-dbs" and so on. The client side doesn't actually need changes, but I'm providing a wrapper to have some symmetry between the client and the server side (it's easier to import a single jsonrpc package). Other than the mapping, the rest of the functionality is identical to net/rpc/jsonrpc.

Example usage

On the server side, change this:

codec := jsonrpc.NewServerCodec(conn)
go server.ServeCodec(codec)

To this:

mapping := map[string]string{
	"add": "Arith.Add",
	"sub": "Arith.Sub",
}
codec := jsonrpc.NewServerCodec(conn, mapping)
go server.ServeCodec(codec)

On the client side things remain the same, optionally changing the name of the method:

c := jsonrpc.NewClient(conn)

args := &Args{2, 2}
var reply Reply
err = c.Call("add", args, &reply)

Documentation

Overview

Package jsonrpc implements a JSON-RPC ClientCodec and ServerCodec for the rpc package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(network, address string) (*rpc.Client, error)

Dial connects to a JSON-RPC server at the specified network address.

func NewClient

func NewClient(conn io.ReadWriteCloser) *rpc.Client

NewClient returns a new rpc.Client to handle requests to the set of services at the other end of the connection.

func NewClientCodec

func NewClientCodec(conn io.ReadWriteCloser) rpc.ClientCodec

NewClientCodec returns a new rpc.ClientCodec using JSON-RPC on conn.

func NewServerCodec

func NewServerCodec(conn io.ReadWriteCloser, mapping map[string]string) rpc.ServerCodec

NewServerCodec returns a new rpc.ServerCodec using JSON-RPC on conn.

func ServeConn

func ServeConn(conn io.ReadWriteCloser, mapping map[string]string)

ServeConn runs the JSON-RPC server on a single connection. ServeConn blocks, serving the connection until the client hangs up. The caller typically invokes ServeConn in a go statement.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL