Browse Source

Merge pull request #10 from tendermint/feature/4-rename-http-clients

rename ClientURI -> URIClient, ClientJSONRPC -> JSONRPCClient
pull/456/head
Anton Kaliaev 8 years ago
committed by GitHub
parent
commit
1a3573bf17
3 changed files with 19 additions and 18 deletions
  1. +1
    -0
      README.md
  2. +9
    -9
      client/http_client.go
  3. +9
    -9
      rpc_test.go

+ 1
- 0
README.md View File

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


+ 9
- 9
client/http_client.go View File

@ -16,7 +16,7 @@ import (
wire "github.com/tendermint/go-wire" 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 { type HTTPClient interface {
Call(method string, params map[string]interface{}, result interface{}) (interface{}, error) 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 // JSON rpc takes params as a slice
type ClientJSONRPC struct {
type JSONRPCClient struct {
address string address string
client *http.Client client *http.Client
} }
func NewClientJSONRPC(remote string) *ClientJSONRPC {
func NewJSONRPCClient(remote string) *JSONRPCClient {
address, client := makeHTTPClient(remote) address, client := makeHTTPClient(remote)
return &ClientJSONRPC{
return &JSONRPCClient{
address: address, address: address,
client: client, 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` // we need this step because we attempt to decode values using `go-wire`
// (handlers.go:176) on the server side // (handlers.go:176) on the server side
encodedParams := make(map[string]interface{}) 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 // URI takes params as a map
type ClientURI struct {
type URIClient struct {
address string address string
client *http.Client client *http.Client
} }
func NewClientURI(remote string) *ClientURI {
func NewURIClient(remote string) *URIClient {
address, client := makeHTTPClient(remote) address, client := makeHTTPClient(remote)
return &ClientURI{
return &URIClient{
address: address, address: address,
client: client, 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) values, err := argsToURLValues(params)
if err != nil { if err != nil {
return nil, err return nil, err


+ 9
- 9
rpc_test.go 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" val := "acbd"
params := map[string]interface{}{ params := map[string]interface{}{
"arg": val, "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" val := "acbd"
params := map[string]interface{}{ params := map[string]interface{}{
"arg": val, "arg": val,
@ -164,22 +164,22 @@ func testWS(t *testing.T, cl *client.WSClient) {
//------------- //-------------
func TestURI_TCP(t *testing.T) { func TestURI_TCP(t *testing.T) {
cl := client.NewClientURI(tcpAddr)
cl := client.NewURIClient(tcpAddr)
testURI(t, cl) testURI(t, cl)
} }
func TestURI_UNIX(t *testing.T) { func TestURI_UNIX(t *testing.T) {
cl := client.NewClientURI(unixAddr)
cl := client.NewURIClient(unixAddr)
testURI(t, cl) testURI(t, cl)
} }
func TestJSONRPC_TCP(t *testing.T) { func TestJSONRPC_TCP(t *testing.T) {
cl := client.NewClientJSONRPC(tcpAddr)
cl := client.NewJSONRPCClient(tcpAddr)
testJSONRPC(t, cl) testJSONRPC(t, cl)
} }
func TestJSONRPC_UNIX(t *testing.T) { func TestJSONRPC_UNIX(t *testing.T) {
cl := client.NewClientJSONRPC(unixAddr)
cl := client.NewJSONRPCClient(unixAddr)
testJSONRPC(t, cl) testJSONRPC(t, cl)
} }
@ -202,7 +202,7 @@ func TestWS_UNIX(t *testing.T) {
} }
func TestHexStringArg(t *testing.T) { func TestHexStringArg(t *testing.T) {
cl := client.NewClientURI(tcpAddr)
cl := client.NewURIClient(tcpAddr)
// should NOT be handled as hex // should NOT be handled as hex
val := "0xabc" val := "0xabc"
params := map[string]interface{}{ params := map[string]interface{}{
@ -220,7 +220,7 @@ func TestHexStringArg(t *testing.T) {
} }
func TestQuotedStringArg(t *testing.T) { func TestQuotedStringArg(t *testing.T) {
cl := client.NewClientURI(tcpAddr)
cl := client.NewURIClient(tcpAddr)
// should NOT be unquoted // should NOT be unquoted
val := "\"abc\"" val := "\"abc\""
params := map[string]interface{}{ params := map[string]interface{}{
@ -248,7 +248,7 @@ func randBytes(t *testing.T) []byte {
} }
func TestByteSliceViaJSONRPC(t *testing.T) { func TestByteSliceViaJSONRPC(t *testing.T) {
cl := client.NewClientJSONRPC(unixAddr)
cl := client.NewJSONRPCClient(unixAddr)
val := randBytes(t) val := randBytes(t)
params := map[string]interface{}{ params := map[string]interface{}{


Loading…
Cancel
Save