From 5f218a43fdad9674c00bc41170602730f034187d Mon Sep 17 00:00:00 2001 From: Emmanuel Odeke Date: Fri, 13 Oct 2017 00:11:20 -0600 Subject: [PATCH] rpc/client: use compile time assertions instead of methods --- rpc/client/httpclient.go | 21 ++++++--------------- rpc/client/localclient.go | 11 ++++------- rpc/client/mock/abci.go | 16 +++++----------- rpc/client/mock/client.go | 4 +--- rpc/client/mock/status.go | 11 ++++------- 5 files changed, 20 insertions(+), 43 deletions(-) diff --git a/rpc/client/httpclient.go b/rpc/client/httpclient.go index b00c97d23..2b78e9767 100644 --- a/rpc/client/httpclient.go +++ b/rpc/client/httpclient.go @@ -39,17 +39,12 @@ func NewHTTP(remote, wsEndpoint string) *HTTP { } } -func (c *HTTP) _assertIsClient() Client { - return c -} - -func (c *HTTP) _assertIsNetworkClient() NetworkClient { - return c -} - -func (c *HTTP) _assertIsEventSwitch() types.EventSwitch { - return c -} +var ( + _ Client = (*HTTP)(nil) + _ NetworkClient = (*HTTP)(nil) + _ types.EventSwitch = (*HTTP)(nil) + _ types.EventSwitch = (*WSEvents)(nil) +) func (c *HTTP) Status() (*ctypes.ResultStatus, error) { result := new(ctypes.ResultStatus) @@ -216,10 +211,6 @@ func newWSEvents(remote, endpoint string) *WSEvents { } } -func (w *WSEvents) _assertIsEventSwitch() types.EventSwitch { - return w -} - // Start is the only way I could think the extend OnStart from // events.eventSwitch. If only it wasn't private... // BaseService.Start -> eventSwitch.OnStart -> WSEvents.Start diff --git a/rpc/client/localclient.go b/rpc/client/localclient.go index 134f935ca..d12a5a84f 100644 --- a/rpc/client/localclient.go +++ b/rpc/client/localclient.go @@ -41,13 +41,10 @@ func NewLocal(node *nm.Node) Local { } } -func (c Local) _assertIsClient() Client { - return c -} - -func (c Local) _assertIsNetworkClient() NetworkClient { - return c -} +var ( + _ Client = Local{} + _ NetworkClient = Local{} +) func (c Local) Status() (*ctypes.ResultStatus, error) { return core.Status() diff --git a/rpc/client/mock/abci.go b/rpc/client/mock/abci.go index db3fa4f1d..a02971342 100644 --- a/rpc/client/mock/abci.go +++ b/rpc/client/mock/abci.go @@ -16,9 +16,11 @@ type ABCIApp struct { App abci.Application } -func (a ABCIApp) _assertABCIClient() client.ABCIClient { - return a -} +var ( + _ client.ABCIClient = ABCIApp{} + _ client.ABCIClient = ABCIMock{} + _ client.ABCIClient = (*ABCIRecorder)(nil) +) func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) { return &ctypes.ResultABCIInfo{a.App.Info(abci.RequestInfo{version.Version})}, nil @@ -67,10 +69,6 @@ type ABCIMock struct { Broadcast Call } -func (m ABCIMock) _assertABCIClient() client.ABCIClient { - return m -} - func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) { res, err := m.Info.GetResponse(nil) if err != nil { @@ -126,10 +124,6 @@ func NewABCIRecorder(client client.ABCIClient) *ABCIRecorder { } } -func (r *ABCIRecorder) _assertABCIClient() client.ABCIClient { - return r -} - type QueryArgs struct { Path string Data data.Bytes diff --git a/rpc/client/mock/client.go b/rpc/client/mock/client.go index f32694edd..fd02ebdf2 100644 --- a/rpc/client/mock/client.go +++ b/rpc/client/mock/client.go @@ -37,9 +37,7 @@ type Client struct { types.EventSwitch } -func (c Client) _assertIsClient() client.Client { - return c -} +var _ client.Client = Client{} // Call is used by recorders to save a call and response. // It can also be used to configure mock responses. diff --git a/rpc/client/mock/status.go b/rpc/client/mock/status.go index af0f5335d..58b29d573 100644 --- a/rpc/client/mock/status.go +++ b/rpc/client/mock/status.go @@ -10,9 +10,10 @@ type StatusMock struct { Call } -func (m *StatusMock) _assertStatusClient() client.StatusClient { - return m -} +var ( + _ client.StatusClient = (*StatusMock)(nil) + _ client.StatusClient = (*StatusRecorder)(nil) +) func (m *StatusMock) Status() (*ctypes.ResultStatus, error) { res, err := m.GetResponse(nil) @@ -36,10 +37,6 @@ func NewStatusRecorder(client client.StatusClient) *StatusRecorder { } } -func (r *StatusRecorder) _assertStatusClient() client.StatusClient { - return r -} - func (r *StatusRecorder) addCall(call Call) { r.Calls = append(r.Calls, call) }