This commit is contained in:
crusader 2017-10-27 12:06:50 +09:00
parent 529bab00a6
commit 445bab7d74
2 changed files with 34 additions and 15 deletions

View File

@ -116,9 +116,14 @@ 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,
reflect.ValueOf(r),
args,
reply,
})

View File

@ -3,7 +3,6 @@ package rpc
import (
"fmt"
"log"
"net/http"
"reflect"
"strings"
"sync"
@ -13,8 +12,8 @@ import (
var (
// Precompute the reflect.Type of error and http.Request
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
typeOfRequest = reflect.TypeOf((*http.Request)(nil)).Elem()
typeOfError = reflect.TypeOf((*error)(nil)).Elem()
// typeOfRequest = reflect.TypeOf((*http.Request)(nil)).Elem()
)
// ----------------------------------------------------------------------------
@ -72,25 +71,40 @@ 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 {
// // 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
}
// 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)
// First argument must be a pointer and must be exported.
args := mtype.In(1)
if args.Kind() != reflect.Ptr || !isExportedOrBuiltin(args) {
continue
}
// Third argument must be a pointer and must be exported.
reply := mtype.In(3)
// Second argument must be a pointer and must be exported.
reply := mtype.In(2)
if reply.Kind() != reflect.Ptr || !isExportedOrBuiltin(reply) {
continue
}
// Method needs one out: error.
if mtype.NumOut() != 1 {
continue