This is an automated email from the ASF dual-hosted git repository.

baze pushed a commit to branch 1.4
in repository https://gitbox.apache.org/repos/asf/dubbo-go.git

commit 8e85afdf48849223cbc1ea86f63ae2d58a41b40a
Author: Patrick <[email protected]>
AuthorDate: Tue Mar 31 19:58:13 2020 +0800

    optimized code
---
 protocol/rest/server/server_impl/go_restful_server.go | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/protocol/rest/server/server_impl/go_restful_server.go 
b/protocol/rest/server/server_impl/go_restful_server.go
index 69f36a5..812699b 100644
--- a/protocol/rest/server/server_impl/go_restful_server.go
+++ b/protocol/rest/server/server_impl/go_restful_server.go
@@ -81,29 +81,28 @@ func (grs *GoRestfulServer) Start(url common.URL) {
 }
 
 func (grs *GoRestfulServer) Deploy(invoker protocol.Invoker, restMethodConfig 
map[string]*config.RestMethodConfig) {
-       svc := common.ServiceMap.GetService(invoker.GetUrl().Protocol, 
strings.TrimPrefix(invoker.GetUrl().Path, "/"))
        for methodName, config := range restMethodConfig {
-               // get method
-               method := svc.Method()[methodName]
-               argsTypes := method.ArgsType()
-               replyType := method.ReplyType()
                ws := new(restful.WebService)
                ws.Path(config.Path).
                        Produces(strings.Split(config.Produces, ",")...).
                        Consumes(strings.Split(config.Consumes, ",")...).
-                       
Route(ws.Method(config.MethodType).To(getFunc(methodName, invoker, argsTypes, 
replyType, config)))
+                       
Route(ws.Method(config.MethodType).To(getFunc(methodName, invoker, config)))
                grs.container.Add(ws)
        }
 
 }
 
-func getFunc(methodName string, invoker protocol.Invoker, argsTypes 
[]reflect.Type,
-       replyType reflect.Type, config *config.RestMethodConfig) func(req 
*restful.Request, resp *restful.Response) {
+func getFunc(methodName string, invoker protocol.Invoker, config 
*config.RestMethodConfig) func(req *restful.Request, resp *restful.Response) {
        return func(req *restful.Request, resp *restful.Response) {
                var (
                        err  error
                        args []interface{}
                )
+               svc := common.ServiceMap.GetService(invoker.GetUrl().Protocol, 
strings.TrimPrefix(invoker.GetUrl().Path, "/"))
+               // get method
+               method := svc.Method()[methodName]
+               argsTypes := method.ArgsType()
+               replyType := method.ReplyType()
                if (len(argsTypes) == 1 || len(argsTypes) == 2 && replyType == 
nil) &&
                        argsTypes[0].String() == "[]interface {}" {
                        args = getArgsInterfaceFromRequest(req, config)

Reply via email to