From cbd9ce01501d23b745ef5cb4513e3efb3cc6b67c Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 27 Oct 2017 13:00:30 +0900 Subject: [PATCH] ing --- protocol/json/client.go | 4 ++-- registry.go | 16 +++++++--------- service_map.go | 24 +----------------------- 3 files changed, 10 insertions(+), 34 deletions(-) diff --git a/protocol/json/client.go b/protocol/json/client.go index e59093a..48af5d7 100644 --- a/protocol/json/client.go +++ b/protocol/json/client.go @@ -36,7 +36,7 @@ type clientResponse struct { // EncodeClientRequest encodes parameters for a JSON-RPC client request. func EncodeClientRequest(method string, args interface{}) ([]byte, error) { c := &clientRequest{ - Version: "2.0", + Version: Version, Method: method, Params: args, ID: uint64(rand.Int63()), @@ -47,7 +47,7 @@ func EncodeClientRequest(method string, args interface{}) ([]byte, error) { // EncodeClientNotify encodes parameters for a JSON-RPC client notification. func EncodeClientNotify(method string, args interface{}) ([]byte, error) { c := &clientRequest{ - Version: "2.0", + Version: Version, Method: method, Params: args, } diff --git a/registry.go b/registry.go index fe39c6e..dac9464 100644 --- a/registry.go +++ b/registry.go @@ -3,6 +3,7 @@ package rpc import ( "fmt" "io" + "log" "reflect" "strings" @@ -61,9 +62,9 @@ func (rr *rpcRegistry) RegisterCodec(codec protocol.Codec, contentType string) { // - The receiver is exported (begins with an upper case letter) or local // (defined in the package registering the service). // - The method name is exported. -// - The method has three arguments: *http.Request, *args, *reply. -// - All three arguments are pointers. -// - The second and third arguments are exported or local. +// - The method has two arguments: *args, *reply. +// - All two arguments are pointers. +// - The first and second arguments are exported or local. // - The method has return type error. // // All other methods are ignored. @@ -98,13 +99,16 @@ func (rr *rpcRegistry) Invoke(contentType string, r io.Reader, w io.Writer, befo return fmt.Errorf("Unrecognized Content-Type: %s", contentType) } + log.Print("codec.NewRequest") // Create a new codec request. codecReq := codec.NewRequest(r) // Get service method to be called. + log.Print("codecReq.Method") method, errMethod := codecReq.Method() if errMethod != nil { return write(codecReq, w, beforeWrite, afterWrite, nil, errMethod) } + log.Print("rr.services.get") serviceSpec, methodSpec, errGet := rr.services.get(method) if errGet != nil { return write(codecReq, w, beforeWrite, afterWrite, nil, errGet) @@ -116,12 +120,6 @@ func (rr *rpcRegistry) Invoke(contentType string, r io.Reader, w io.Writer, befo } // Call the service method. reply := reflect.New(methodSpec.replyType) - // errValue := methodSpec.method.Func.Call([]reflect.Value{ - // serviceSpec.rcvr, - // reflect.ValueOf(r), - // args, - // reply, - // }) errValue := methodSpec.method.Func.Call([]reflect.Value{ serviceSpec.rcvr, args, diff --git a/service_map.go b/service_map.go index f3a7be7..0e76035 100644 --- a/service_map.go +++ b/service_map.go @@ -2,7 +2,6 @@ package rpc import ( "fmt" - "log" "reflect" "strings" "sync" @@ -13,7 +12,6 @@ import ( var ( // Precompute the reflect.Type of error and http.Request typeOfError = reflect.TypeOf((*error)(nil)).Elem() - // typeOfRequest = reflect.TypeOf((*http.Request)(nil)).Elem() ) // ---------------------------------------------------------------------------- @@ -62,7 +60,7 @@ func (m *serviceMap) register(rcvr interface{}, name string) error { return fmt.Errorf("rpc: no service name for type %q", s.rcvrType.String()) } - log.Printf("method count of service[%s] is %d", s.name, s.rcvrType.NumMethod()) + // Setup methods. for i := 0; i < s.rcvrType.NumMethod(); i++ { method := s.rcvrType.Method(i) @@ -71,25 +69,6 @@ func (m *serviceMap) register(rcvr interface{}, name string) error { if method.PkgPath != "" { continue } - // // Method needs four ins: receiver, *http.Request, *args, *reply. - // if mtype.NumIn() != 4 { - // continue - // } - // // First argument must be a pointer and must be http.Request. - // reqType := mtype.In(1) - // if reqType.Kind() != reflect.Ptr || reqType.Elem() != typeOfRequest { - // continue - // } - // // Second argument must be a pointer and must be exported. - // args := mtype.In(2) - // if args.Kind() != reflect.Ptr || !isExportedOrBuiltin(args) { - // continue - // } - // // Third argument must be a pointer and must be exported. - // reply := mtype.In(3) - // if reply.Kind() != reflect.Ptr || !isExportedOrBuiltin(reply) { - // continue - // } // Method needs four ins: receiver, *args, *reply. if mtype.NumIn() != 3 { continue @@ -117,7 +96,6 @@ func (m *serviceMap) register(rcvr interface{}, name string) error { argsType: args.Elem(), replyType: reply.Elem(), } - log.Printf("The name of service[%s] method is %s", s.name, method.Name) } if len(s.methods) == 0 { return fmt.Errorf("rpc: %q has no exported methods of suitable type",