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

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


The following commit(s) were added to refs/heads/develop by this push:
     new 01e176524 feat: suport new triple generic call (#2818)
01e176524 is described below

commit 01e1765240f7b3754da282a29047f05c5f299c99
Author: marsevilspirit <[email protected]>
AuthorDate: Sat Apr 5 22:28:46 2025 +0800

    feat: suport new triple generic call (#2818)
    
    * support new triple generic call
    
    * update
    
    * add comment
---
 common/extension/logger.go                |  1 -
 filter/generic/service_filter.go          |  2 +-
 protocol/triple/server.go                 | 26 ++++++++++++++++++++++++--
 protocol/triple/triple_protocol/server.go | 15 ++++++++++++++-
 4 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/common/extension/logger.go b/common/extension/logger.go
index a6e0cb826..1010c5dc6 100644
--- a/common/extension/logger.go
+++ b/common/extension/logger.go
@@ -34,7 +34,6 @@ func SetLogger(driver string, log func(config *common.URL) 
(logger.Logger, error
 }
 
 func GetLogger(driver string, config *common.URL) (logger.Logger, error) {
-
        if logs[driver] != nil {
                return logs[driver](config)
        } else {
diff --git a/filter/generic/service_filter.go b/filter/generic/service_filter.go
index c9a97c3c5..be71c22c3 100644
--- a/filter/generic/service_filter.go
+++ b/filter/generic/service_filter.go
@@ -70,7 +70,7 @@ func (f *genericServiceFilter) Invoke(ctx context.Context, 
invoker protocol.Invo
        types := invocation.Arguments()[1]
        args := invocation.Arguments()[2].([]hessian.Object)
 
-       logger.Debugf(`received a generic invocation: 
+       logger.Debugf(`received a generic invocation:
                MethodName: %s,
                Types: %s,
                Args: %s
diff --git a/protocol/triple/server.go b/protocol/triple/server.go
index 766427310..74d608333 100644
--- a/protocol/triple/server.go
+++ b/protocol/triple/server.go
@@ -29,6 +29,8 @@ import (
 import (
        "github.com/dubbogo/gost/log/logger"
 
+       hessian "github.com/apache/dubbo-go-hessian2"
+
        grpc_go "github.com/dubbogo/grpc-go"
 
        "github.com/dustin/go-humanize"
@@ -395,7 +397,10 @@ func createServiceInfoWithReflection(svc 
common.RPCService) *common.ServiceInfo
        val := reflect.ValueOf(svc)
        typ := reflect.TypeOf(svc)
        methodNum := val.NumMethod()
-       methodInfos := make([]common.MethodInfo, methodNum)
+
+       // +1 for generic call method
+       methodInfos := make([]common.MethodInfo, 0, methodNum+1)
+
        for i := 0; i < methodNum; i++ {
                methodType := typ.Method(i)
                if methodType.Name == "Reference" {
@@ -424,8 +429,25 @@ func createServiceInfoWithReflection(svc 
common.RPCService) *common.ServiceInfo
                                return params
                        },
                }
-               methodInfos[i] = methodInfo
+               methodInfos = append(methodInfos, methodInfo)
        }
+
+       // only support no-idl mod call unary
+       genericMethodInfo := common.MethodInfo{
+               Name: "$invoke",
+               Type: constant.CallUnary,
+               ReqInitFunc: func() interface{} {
+                       params := make([]interface{}, 3)
+                       // params must be pointer
+                       params[0] = func(s string) *string { return &s 
}("methodName") // methodName *string
+                       params[1] = &[]string{}                                 
       // argv type  *[]string
+                       params[2] = &[]hessian.Object{}                         
       // argv       *[]hessian.Object
+                       return params
+               },
+       }
+
+       methodInfos = append(methodInfos, genericMethodInfo)
+
        info.Methods = methodInfos
 
        return &info
diff --git a/protocol/triple/triple_protocol/server.go 
b/protocol/triple/triple_protocol/server.go
index 26055beaa..487ef3a5d 100644
--- a/protocol/triple/triple_protocol/server.go
+++ b/protocol/triple/triple_protocol/server.go
@@ -30,6 +30,10 @@ import (
        "golang.org/x/net/http2/h2c"
 )
 
+import (
+       "github.com/dubbogo/gost/log/logger"
+)
+
 type Server struct {
        mu       sync.Mutex
        mux      *http.ServeMux
@@ -157,9 +161,18 @@ func (s *Server) RegisterCompatStreamHandler(
        return nil
 }
 
+func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+       handler, pattern := s.mux.Handler(r)
+       if pattern == "" {
+               logger.Warnf("404: didn't register this method - %s\n", 
r.URL.Path)
+       }
+
+       handler.ServeHTTP(w, r)
+}
+
 func (s *Server) Run() error {
        // todo(DMwangnima): deal with TLS
-       s.httpSrv.Handler = h2c.NewHandler(s.mux, &http2.Server{})
+       s.httpSrv.Handler = h2c.NewHandler(s, &http2.Server{})
 
        if err := s.httpSrv.ListenAndServe(); err != nil {
                return err

Reply via email to