rename ClientURI -> URIClient, ClientJSONRPC -> JSONRPCClient (Refs #4)

This commit is contained in:
Anton Kaliaev 2017-03-08 01:22:35 +04:00
parent 759060f47e
commit e6c083f589
No known key found for this signature in database
GPG Key ID: 7B6881D965918214
3 changed files with 19 additions and 18 deletions

View File

@ -118,6 +118,7 @@ BREAKING CHANGES:
- removed `Client` empty interface
- `ClientJSONRPC#Call` `params` argument became a map
- rename `ClientURI` -> `URIClient`, `ClientJSONRPC` -> `JSONRPCClient`
IMPROVEMENTS:

View File

@ -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

View File

@ -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{}{