rpc: golint comments and warnings

This commit is contained in:
Kiel barry 2018-06-05 16:44:51 -07:00
parent 857f70e56b
commit 968860b2a2
6 changed files with 17 additions and 15 deletions

View file

@ -631,7 +631,7 @@ func (c *Client) closeRequestOps(err error) {
} }
for id, sub := range c.subs { for id, sub := range c.subs {
delete(c.subs, id) 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. // Unsubscribe unsubscribes the notification and closes the error channel.
// It can safely be called more than once. // It can safely be called more than once.
func (sub *ClientSubscription) Unsubscribe() { func (sub *ClientSubscription) Unsubscribe() {
sub.quitWithError(nil, true) sub.quitWithError(true, nil)
sub.errOnce.Do(func() { close(sub.err) }) 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() { sub.quitOnce.Do(func() {
// The dispatch loop won't be able to execute the unsubscribe call // The dispatch loop won't be able to execute the unsubscribe call
// if it is blocked on deliver. Close sub.quit first because it // if it is blocked on deliver. Close sub.quit first because it

View file

@ -174,6 +174,7 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server) *http.Server {
} }
type contextKey string type contextKey string
func contextString(c contextKey) string { func contextString(c contextKey) string {
return string(c) return string(c)
} }
@ -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 // untilEOF and writes the response to w and order the server to process a
// single request. // single request.
ctx := r.Context() 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, sch, r.Proto)
ctx = context.WithValue(ctx, loc, r.Host) ctx = context.WithValue(ctx, loc, r.Host)

View file

@ -275,8 +275,9 @@ func parseBatchRequest(incomingMsg json.RawMessage) ([]rpcRequest, bool, Error)
func (c *jsonCodec) ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) { func (c *jsonCodec) ParseRequestArguments(argTypes []reflect.Type, params interface{}) ([]reflect.Value, Error) {
if args, ok := params.(json.RawMessage); !ok { if args, ok := params.(json.RawMessage); !ok {
return nil, &invalidParamsError{"Invalid params supplied"} 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 // parsePositionalArguments tries to parse the given args to an array of values with the

View file

@ -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 // register a default service which will provide meta information about the RPC service such as the services and
// methods it offers. // methods it offers.
rpcService := &Service{server} rpcService := &RPCService{server}
server.RegisterName(MetadataAPI, rpcService) server.RegisterName(MetadataAPI, rpcService)
return server return server
} }
// Service gives meta information about the server. // RPCService gives meta information about the server.
// e.g. gives information about the loaded modules. // e.g. gives information about the loaded modules.
type Service struct { type RPCService struct {
server *Server server *Server
} }
// Modules returns the list of RPC services with their version number // 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) modules := make(map[string]string)
for name := range s.server.services { for name := range s.server.services {
modules[name] = "1.0" modules[name] = "1.0"

View file

@ -59,8 +59,8 @@ func (s *Service) Rets() (string, error) {
return "", nil return "", nil
} }
func (s *Service) InvalidRets1() (string, error) { func (s *Service) InvalidRets1() (error, string) {
return "", nil return nil, ""
} }
func (s *Service) InvalidRets2() (string, string) { func (s *Service) InvalidRets2() (string, string) {

View file

@ -195,7 +195,7 @@ func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSucces
if _, found := msg["result"]; found { if _, found := msg["result"]; found {
successes <- jsonSuccessResponse{ successes <- jsonSuccessResponse{
Version: msg["jsonrpc"].(string), Version: msg["jsonrpc"].(string),
Id: msg["id"], ID: msg["id"],
Result: msg["result"], Result: msg["result"],
} }
continue continue
@ -204,7 +204,7 @@ func waitForMessages(t *testing.T, in *json.Decoder, successes chan<- jsonSucces
params := msg["params"].(map[string]interface{}) params := msg["params"].(map[string]interface{})
failures <- jsonErrResponse{ failures <- jsonErrResponse{
Version: msg["jsonrpc"].(string), Version: msg["jsonrpc"].(string),
Id: msg["id"], ID: msg["id"],
Error: jsonError{int(params["subscription"].(float64)), params["message"].(string), params["data"]}, Error: jsonError{int(params["subscription"].(float64)), params["message"].(string), params["data"]},
} }
continue continue
@ -304,7 +304,7 @@ func TestSubscriptionMultipleNamespaces(t *testing.T) {
case err := <-errors: case err := <-errors:
t.Fatal(err) t.Fatal(err)
case suc := <-successes: // subscription created 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: case failure := <-failures:
t.Errorf("received error: %v", failure.Error) t.Errorf("received error: %v", failure.Error)
case notification := <-notifications: case notification := <-notifications: