Browse Source

rpc/client: use compile time assertions instead of methods

pull/741/head
Emmanuel Odeke 7 years ago
parent
commit
5f218a43fd
No known key found for this signature in database GPG Key ID: 1CA47A292F89DD40
5 changed files with 20 additions and 43 deletions
  1. +6
    -15
      rpc/client/httpclient.go
  2. +4
    -7
      rpc/client/localclient.go
  3. +5
    -11
      rpc/client/mock/abci.go
  4. +1
    -3
      rpc/client/mock/client.go
  5. +4
    -7
      rpc/client/mock/status.go

+ 6
- 15
rpc/client/httpclient.go View File

@ -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) { func (c *HTTP) Status() (*ctypes.ResultStatus, error) {
result := new(ctypes.ResultStatus) 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 // Start is the only way I could think the extend OnStart from
// events.eventSwitch. If only it wasn't private... // events.eventSwitch. If only it wasn't private...
// BaseService.Start -> eventSwitch.OnStart -> WSEvents.Start // BaseService.Start -> eventSwitch.OnStart -> WSEvents.Start


+ 4
- 7
rpc/client/localclient.go View File

@ -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) { func (c Local) Status() (*ctypes.ResultStatus, error) {
return core.Status() return core.Status()


+ 5
- 11
rpc/client/mock/abci.go View File

@ -16,9 +16,11 @@ type ABCIApp struct {
App abci.Application 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) { func (a ABCIApp) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
return &ctypes.ResultABCIInfo{a.App.Info(abci.RequestInfo{version.Version})}, nil return &ctypes.ResultABCIInfo{a.App.Info(abci.RequestInfo{version.Version})}, nil
@ -67,10 +69,6 @@ type ABCIMock struct {
Broadcast Call Broadcast Call
} }
func (m ABCIMock) _assertABCIClient() client.ABCIClient {
return m
}
func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) { func (m ABCIMock) ABCIInfo() (*ctypes.ResultABCIInfo, error) {
res, err := m.Info.GetResponse(nil) res, err := m.Info.GetResponse(nil)
if err != 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 { type QueryArgs struct {
Path string Path string
Data data.Bytes Data data.Bytes


+ 1
- 3
rpc/client/mock/client.go View File

@ -37,9 +37,7 @@ type Client struct {
types.EventSwitch 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. // Call is used by recorders to save a call and response.
// It can also be used to configure mock responses. // It can also be used to configure mock responses.


+ 4
- 7
rpc/client/mock/status.go View File

@ -10,9 +10,10 @@ type StatusMock struct {
Call 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) { func (m *StatusMock) Status() (*ctypes.ResultStatus, error) {
res, err := m.GetResponse(nil) 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) { func (r *StatusRecorder) addCall(call Call) {
r.Calls = append(r.Calls, call) r.Calls = append(r.Calls, call)
} }


Loading…
Cancel
Save