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 {
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

View file

@ -174,6 +174,7 @@ func NewHTTPServer(cors []string, vhosts []string, srv *Server) *http.Server {
}
type contextKey string
func contextString(c contextKey) string {
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
// 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)

View file

@ -275,9 +275,10 @@ 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)
}
}
// parsePositionalArguments tries to parse the given args to an array of values with the
// given types. It returns the parsed values or an error when the args could not be

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
// 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"

View file

@ -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) {

View file

@ -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: