From e6c083f589d93d5cada7c5e9fff1c3c05873a167 Mon Sep 17 00:00:00 2001 From: Anton Kaliaev Date: Wed, 8 Mar 2017 01:22:35 +0400 Subject: [PATCH] rename ClientURI -> URIClient, ClientJSONRPC -> JSONRPCClient (Refs #4) --- README.md | 1 + client/http_client.go | 18 +++++++++--------- rpc_test.go | 18 +++++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 149ecdf5..06a67903 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ BREAKING CHANGES: - removed `Client` empty interface - `ClientJSONRPC#Call` `params` argument became a map +- rename `ClientURI` -> `URIClient`, `ClientJSONRPC` -> `JSONRPCClient` IMPROVEMENTS: diff --git a/client/http_client.go b/client/http_client.go index 5030323b..96bae9d9 100644 --- a/client/http_client.go +++ b/client/http_client.go @@ -16,7 +16,7 @@ import ( wire "github.com/tendermint/go-wire" ) -// HTTPClient is a common interface for ClientJSONRPC and ClientURI. +// HTTPClient is a common interface for JSONRPCClient and URIClient. type HTTPClient interface { Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) } @@ -54,20 +54,20 @@ func makeHTTPClient(remoteAddr string) (string, *http.Client) { //------------------------------------------------------------------------------------ // JSON rpc takes params as a slice -type ClientJSONRPC struct { +type JSONRPCClient struct { address string client *http.Client } -func NewClientJSONRPC(remote string) *ClientJSONRPC { +func NewJSONRPCClient(remote string) *JSONRPCClient { address, client := makeHTTPClient(remote) - return &ClientJSONRPC{ + return &JSONRPCClient{ address: address, client: client, } } -func (c *ClientJSONRPC) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { +func (c *JSONRPCClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { // we need this step because we attempt to decode values using `go-wire` // (handlers.go:176) on the server side encodedParams := make(map[string]interface{}) @@ -105,20 +105,20 @@ func (c *ClientJSONRPC) Call(method string, params map[string]interface{}, resul //------------------------------------------------------------- // URI takes params as a map -type ClientURI struct { +type URIClient struct { address string client *http.Client } -func NewClientURI(remote string) *ClientURI { +func NewURIClient(remote string) *URIClient { address, client := makeHTTPClient(remote) - return &ClientURI{ + return &URIClient{ address: address, client: client, } } -func (c *ClientURI) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { +func (c *URIClient) Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) { values, err := argsToURLValues(params) if err != nil { return nil, err diff --git a/rpc_test.go b/rpc_test.go index 334909f1..b1ae2566 100644 --- a/rpc_test.go +++ b/rpc_test.go @@ -98,7 +98,7 @@ func init() { } -func testURI(t *testing.T, cl *client.ClientURI) { +func testURI(t *testing.T, cl *client.URIClient) { val := "acbd" params := map[string]interface{}{ "arg": val, @@ -114,7 +114,7 @@ func testURI(t *testing.T, cl *client.ClientURI) { } } -func testJSONRPC(t *testing.T, cl *client.ClientJSONRPC) { +func testJSONRPC(t *testing.T, cl *client.JSONRPCClient) { val := "acbd" params := map[string]interface{}{ "arg": val, @@ -164,22 +164,22 @@ func testWS(t *testing.T, cl *client.WSClient) { //------------- func TestURI_TCP(t *testing.T) { - cl := client.NewClientURI(tcpAddr) + cl := client.NewURIClient(tcpAddr) testURI(t, cl) } func TestURI_UNIX(t *testing.T) { - cl := client.NewClientURI(unixAddr) + cl := client.NewURIClient(unixAddr) testURI(t, cl) } func TestJSONRPC_TCP(t *testing.T) { - cl := client.NewClientJSONRPC(tcpAddr) + cl := client.NewJSONRPCClient(tcpAddr) testJSONRPC(t, cl) } func TestJSONRPC_UNIX(t *testing.T) { - cl := client.NewClientJSONRPC(unixAddr) + cl := client.NewJSONRPCClient(unixAddr) testJSONRPC(t, cl) } @@ -202,7 +202,7 @@ func TestWS_UNIX(t *testing.T) { } func TestHexStringArg(t *testing.T) { - cl := client.NewClientURI(tcpAddr) + cl := client.NewURIClient(tcpAddr) // should NOT be handled as hex val := "0xabc" params := map[string]interface{}{ @@ -220,7 +220,7 @@ func TestHexStringArg(t *testing.T) { } func TestQuotedStringArg(t *testing.T) { - cl := client.NewClientURI(tcpAddr) + cl := client.NewURIClient(tcpAddr) // should NOT be unquoted val := "\"abc\"" params := map[string]interface{}{ @@ -248,7 +248,7 @@ func randBytes(t *testing.T) []byte { } func TestByteSliceViaJSONRPC(t *testing.T) { - cl := client.NewClientJSONRPC(unixAddr) + cl := client.NewJSONRPCClient(unixAddr) val := randBytes(t) params := map[string]interface{}{