From 968860b2a23e153e00eb20b6225112eb3afa1fed Mon Sep 17 00:00:00 2001 From: Kiel barry Date: Tue, 5 Jun 2018 16:44:51 -0700 Subject: [PATCH] rpc: golint comments and warnings --- rpc/client.go | 6 +++--- rpc/http.go | 5 +++-- rpc/json.go | 3 ++- rpc/server.go | 8 ++++---- rpc/server_test.go | 4 ++-- rpc/subscription_test.go | 6 +++--- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/rpc/client.go b/rpc/client.go index 5cdeb241e9..ceb60fafed 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -631,7 +631,7 @@ func (c *Client) closeRequestOps(err error) { } for id, sub := range c.subs { delete(c.subs, id) - sub.quitWithError(err, false) + sub.quitWithError(false, err) } } @@ -755,11 +755,11 @@ func (sub *ClientSubscription) Err() <-chan error { // Unsubscribe unsubscribes the notification and closes the error channel. // It can safely be called more than once. func (sub *ClientSubscription) Unsubscribe() { - sub.quitWithError(nil, true) + sub.quitWithError(true, nil) sub.errOnce.Do(func() { close(sub.err) }) } -func (sub *ClientSubscription) quitWithError(err error, unsubscribeServer bool) { +func (sub *ClientSubscription) quitWithError(unsubscribeServer bool, err error) { sub.quitOnce.Do(func() { // The dispatch loop won't be able to execute the unsubscribe call // if it is blocked on deliver. Close sub.quit first because it diff --git a/rpc/http.go b/rpc/http.go index eef1eb8393..04f2c67c4c 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -174,8 +174,9 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server) *http.Server { } type contextKey string + func contextString(c contextKey) string { - return string(c) + return string(c) } // ServeHTTP serves JSON-RPC requests over HTTP. @@ -195,7 +196,7 @@ func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { // untilEOF and writes the response to w and order the server to process a // single request. ctx := r.Context() - ctx = context.WithValue(ctx, remote, r.RemoteAddr) + ctx = context.WithValue(ctx, rem, r.RemoteAddr) ctx = context.WithValue(ctx, sch, r.Proto) ctx = context.WithValue(ctx, loc, r.Host) diff --git a/rpc/json.go b/rpc/json.go index dd4e0edeec..ac054ffff5 100644 --- a/rpc/json.go +++ b/rpc/json.go @@ -275,8 +275,9 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error) func (c *jsonCodec) ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) { if args, ok := params.(json.RawMessage); !ok { return nil, &invalidParamsError{"Invalid params supplied"} + } else { + return parsePositionalArguments(args, argTypes) } - return parsePositionalArguments(args, argTypes) } // parsePositionalArguments tries to parse the given args to an array of values with the diff --git a/rpc/server.go b/rpc/server.go index 9f7ff36584..9901f9b220 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -52,20 +52,20 @@ func NewServer() *Server { // register a default service which will provide meta information about the RPC service such as the services and // methods it offers. - rpcService := &Service{server} + rpcService := &RPCService{server} server.RegisterName(MetadataAPI, rpcService) return server } -// Service gives meta information about the server. +// RPCService gives meta information about the server. // e.g. gives information about the loaded modules. -type Service struct { +type RPCService struct { server *Server } // Modules returns the list of RPC services with their version number -func (s *Service) Modules() map[string]string { +func (s *RPCService) Modules() map[string]string { modules := make(map[string]string) for name := range s.server.services { modules[name] = "1.0" diff --git a/rpc/server_test.go b/rpc/server_test.go index 0f76826084..90d62f26d8 100644 --- a/rpc/server_test.go +++ b/rpc/server_test.go @@ -59,8 +59,8 @@ func (s *Service) Rets() (string, error) { return "", nil } -func (s *Service) InvalidRets1() (string, error) { - return "", nil +func (s *Service) InvalidRets1() (error, string) { + return nil, "" } func (s *Service) InvalidRets2() (string, string) { diff --git a/rpc/subscription_test.go b/rpc/subscription_test.go index 0ba177e63b..96c80b74ae 100644 --- a/rpc/subscription_test.go +++ b/rpc/subscription_test.go @@ -195,7 +195,7 @@ func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSucces if _, found := msg["result"]; found { successes <- jsonSuccessResponse{ Version: msg["jsonrpc"].(string), - Id: msg["id"], + ID: msg["id"], Result: msg["result"], } continue @@ -204,7 +204,7 @@ func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSucces params := msg["params"].(map[string]interface{}) failures <- jsonErrResponse{ Version: msg["jsonrpc"].(string), - Id: msg["id"], + ID: msg["id"], Error: jsonError{int(params["subscription"].(float64)), params["message"].(string), params["data"]}, } continue @@ -304,7 +304,7 @@ func TestSubscriptionMultipleNamespaces(t *testing.T) { case err := <-errors: t.Fatal(err) case suc := <-successes: // subscription created - subids[namespaces[int(suc.Id.(float64))]] = suc.Result.(string) + subids[namespaces[int(suc.ID.(float64))]] = suc.Result.(string) case failure := <-failures: t.Errorf("received error: %v", failure.Error) case notification := <-notifications: