From 3b45ab3a667d96ffae47457179f2fe8b5d0c9b98 Mon Sep 17 00:00:00 2001 From: Beyang Liu Date: Fri, 28 Oct 2016 16:33:31 -0700 Subject: [PATCH] add JSONRPC2 interface --- jsonrpc2.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/jsonrpc2.go b/jsonrpc2.go index 5f49f9f..856a815 100644 --- a/jsonrpc2.go +++ b/jsonrpc2.go @@ -17,6 +17,21 @@ import ( "sync" ) +// JSONRPC2 describes an interface for issuing requests that speak the +// JSON-RPC 2 protocol. It isn't really necessary for this package +// itself, but is useful for external users that use the interface as +// an API boundary. +type JSONRPC2 interface { + // Call issues a standard request (http://www.jsonrpc.org/specification#request_object). + Call(ctx context.Context, method string, params, result interface{}, opt ...CallOption) error + + // Notify issues a notification request (http://www.jsonrpc.org/specification#notification). + Notify(ctx context.Context, method string, params interface{}, opt ...CallOption) error + + // Close closes the underlying connection, if it exists. + Close() error +} + // Request represents a JSON-RPC request or // notification. See // http://www.jsonrpc.org/specification#request_object and @@ -203,6 +218,8 @@ type Conn struct { onSend func(*Request, *Response) } +var _ JSONRPC2 = (*Conn)(nil) + // ErrClosed indicates that the JSON-RPC connection is closed (or in // the process of closing). var ErrClosed = errors.New("jsonrpc2: connection is closed")