From 5377dcd04bbdff0e19ddd33bcbf78b9bf14fb879 Mon Sep 17 00:00:00 2001
From: Benjamin Bollen <ben@monax.io>
Date: Tue, 31 Jan 2017 16:59:22 +0100
Subject: [PATCH] rpc: add AssertIsRPCResponse as marker method for restricting
 implementation of interface to actual RPCResponse types

---
 rpc/jsonrpc.go | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/rpc/jsonrpc.go b/rpc/jsonrpc.go
index 4a28c4b1..73cb0cb6 100644
--- a/rpc/jsonrpc.go
+++ b/rpc/jsonrpc.go
@@ -40,7 +40,9 @@ type (
 
 	// RPCResponse MUST follow the JSON-RPC specification for Response object
 	// reference: http://www.jsonrpc.org/specification#response_object
-	RPCResponse interface{}
+	RPCResponse interface {
+		AssertIsRPCResponse() bool
+	}
 
 	// RPCResultResponse MUST NOT contain the error member if no error occurred
 	RPCResultResponse struct {
@@ -82,3 +84,15 @@ func NewRPCErrorResponse(id string, code int, message string) RPCResponse {
 		JSONRPC: "2.0",
 	})
 }
+
+// AssertIsRPCResponse implements a marker method for RPCResultResponse
+// to implement the interface RPCResponse
+func (rpcResultResponse *RPCResultResponse) AssertIsRPCResponse() bool {
+	return true
+}
+
+// AssertIsRPCResponse implements a marker method for RPCErrorResponse
+// to implement the interface RPCResponse
+func (rpcErrorResponse *RPCErrorResponse) AssertIsRPCResponse() bool {
+	return true
+}
-- 
GitLab