Merge pull request #741 from tendermint/client-compile-time-assertions

rpc/client: use compile time assertions instead of methods
This commit is contained in:
Ethan Buchman 2017-10-17 03:41:24 -04:00 committed by GitHub
commit b234f7aba2
5 changed files with 20 additions and 43 deletions

View File

@ -39,17 +39,12 @@ func NewHTTP(remote, wsEndpoint string) *HTTP {
} }
} }
func (c *HTTP) _assertIsClient() Client { var (
return c _ Client = (*HTTP)(nil)
} _ NetworkClient = (*HTTP)(nil)
_ types.EventSwitch = (*HTTP)(nil)
func (c *HTTP) _assertIsNetworkClient() NetworkClient { _ types.EventSwitch = (*WSEvents)(nil)
return c )
}
func (c *HTTP) _assertIsEventSwitch() types.EventSwitch {
return c
}
func (c *HTTP) Status() (*ctypes.ResultStatus, error) { func (c *HTTP) Status() (*ctypes.ResultStatus, error) {
result := new(ctypes.ResultStatus) result := new(ctypes.ResultStatus)
@ -220,10 +215,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

View File

@ -41,13 +41,10 @@ func NewLocal(node *nm.Node) Local {
} }
} }
func (c Local) _assertIsClient() Client { var (
return c _ Client = Local{}
} _ NetworkClient = Local{}
)
func (c Local) _assertIsNetworkClient() NetworkClient {
return c
}
func (c Local) Status() (*ctypes.ResultStatus, error) { func (c Local) Status() (*ctypes.ResultStatus, error) {
return core.Status() return core.Status()

View File

@ -16,9 +16,11 @@ type ABCIApp struct {
App abci.Application App abci.Application
} }
func (a ABCIApp) _assertABCIClient() client.ABCIClient { var (
return a _ 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
@ -71,10 +73,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 {
@ -134,10 +132,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

View File

@ -37,9 +37,7 @@ type Client struct {
types.EventSwitch types.EventSwitch
} }
func (c Client) _assertIsClient() client.Client { var _ client.Client = Client{}
return c
}
// 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.

View File

@ -10,9 +10,10 @@ type StatusMock struct {
Call Call
} }
func (m *StatusMock) _assertStatusClient() client.StatusClient { var (
return m _ 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)
} }