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 e1fc8ed56 Refactor : remove protocol config (#3212)
e1fc8ed56 is described below

commit e1fc8ed56f4257004fb149104cc964a13eea56d6
Author: 翎 <[email protected]>
AuthorDate: Mon Mar 2 00:01:40 2026 +0800

    Refactor : remove protocol config (#3212)
    
    * feat: remove config
    
    * fix(dubbo3): remove unused sentinel type in internal client file
---
 protocol/dubbo3/internal/client.go          | 29 -----------------------------
 protocol/dubbo3/internal/server.go          | 26 --------------------------
 protocol/grpc/client.go                     | 23 +++++++++++++++++++----
 protocol/grpc/client_test.go                |  6 ++----
 protocol/grpc/grpc_invoker.go               | 12 ++++++++++++
 protocol/grpc/grpc_invoker_test.go          |  2 ++
 protocol/grpc/internal/helloworld/client.go |  9 ---------
 protocol/grpc/internal/routeguide/client.go |  9 ---------
 8 files changed, 35 insertions(+), 81 deletions(-)

diff --git a/protocol/dubbo3/internal/client.go 
b/protocol/dubbo3/internal/client.go
deleted file mode 100644
index 69c03db23..000000000
--- a/protocol/dubbo3/internal/client.go
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package internal
-
-import (
-       "dubbo.apache.org/dubbo-go/v3/config"
-)
-
-// TODO: After the config is removed, remove the test
-func init() {
-       // for pb client
-       
config.SetConsumerServiceByInterfaceName("org.apache.dubbo.DubboGreeterImpl", 
&GreeterClientImpl{})
-       config.SetConsumerService(&GreeterClientImpl{})
-}
diff --git a/protocol/dubbo3/internal/server.go 
b/protocol/dubbo3/internal/server.go
index 9966635c8..d47b1e02e 100644
--- a/protocol/dubbo3/internal/server.go
+++ b/protocol/dubbo3/internal/server.go
@@ -26,8 +26,6 @@ import (
 )
 
 import (
-       "dubbo.apache.org/dubbo-go/v3/common"
-       "dubbo.apache.org/dubbo-go/v3/config"
        _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"
        _ "dubbo.apache.org/dubbo-go/v3/metrics/prometheus"
        _ "dubbo.apache.org/dubbo-go/v3/proxy/proxy_factory"
@@ -43,27 +41,3 @@ func (s *Server) SayHello(ctx context.Context, in 
*HelloRequest) (*HelloReply, e
        log.Infof("Received: %v", in.GetName())
        return &HelloReply{Message: "Hello " + in.GetName()}, nil
 }
-
-// InitDubboServer creates global gRPC server.
-// TODO: After the config is removed, remove the test
-func InitDubboServer() {
-       serviceConfig := config.NewServiceConfigBuilder().
-               SetInterface("org.apache.dubbo.DubboGreeterImpl").
-               SetProtocolIDs("tripleKey").Build()
-
-       providerConfig := 
config.NewProviderConfigBuilder().SetServices(map[string]*config.ServiceConfig{
-               common.GetReference(&Server{}): serviceConfig,
-       }).Build()
-
-       protocolConfig := 
config.NewProtocolConfigBuilder().SetName("tri").SetPort("20003").Build()
-
-       rootConfig := 
config.NewRootConfigBuilder().SetProvider(providerConfig).SetProtocols(map[string]*config.ProtocolConfig{
-               "tripleKey": protocolConfig,
-       }).Build()
-
-       config.SetProviderService(&Server{})
-       if err := rootConfig.Init(); err != nil {
-               panic(err)
-       }
-       rootConfig.Start()
-}
diff --git a/protocol/grpc/client.go b/protocol/grpc/client.go
index 644dd45a1..b4bd37025 100644
--- a/protocol/grpc/client.go
+++ b/protocol/grpc/client.go
@@ -214,9 +214,24 @@ func clientInit(url *common.URL) {
 }
 
 func getInvoker(impl any, conn *grpc.ClientConn) any {
-       var in []reflect.Value
-       in = append(in, reflect.ValueOf(conn))
-       method := reflect.ValueOf(impl).MethodByName("GetDubboStub")
-       res := method.Call(in)
+       if impl == nil {
+               return nil
+       }
+
+       implValue := reflect.ValueOf(impl)
+       if !implValue.IsValid() {
+               return nil
+       }
+
+       method := implValue.MethodByName("GetDubboStub")
+       if !method.IsValid() {
+               return nil
+       }
+
+       res := method.Call([]reflect.Value{reflect.ValueOf(conn)})
+       if len(res) == 0 {
+               return nil
+       }
+
        return res[0].Interface()
 }
diff --git a/protocol/grpc/client_test.go b/protocol/grpc/client_test.go
index 34e4e34a4..0091779b3 100644
--- a/protocol/grpc/client_test.go
+++ b/protocol/grpc/client_test.go
@@ -48,8 +48,7 @@ func TestUnaryClient(t *testing.T) {
        cli, err := NewClient(url)
        require.NoError(t, err)
 
-       impl := &helloworld.GreeterClientImpl{}
-       client := impl.GetDubboStub(cli.ClientConn)
+       client := helloworld.NewGreeterClient(cli.ClientConn)
        result, err := client.SayHello(context.Background(), 
&helloworld.HelloRequest{Name: "request name"})
        require.NoError(t, err)
        assert.Equal(t, &helloworld.HelloReply{Message: "Hello request name"}, 
result)
@@ -67,8 +66,7 @@ func TestStreamClient(t *testing.T) {
        cli, err := NewClient(url)
        require.NoError(t, err)
 
-       impl := &routeguide.RouteGuideClientImpl{}
-       client := impl.GetDubboStub(cli.ClientConn)
+       client := routeguide.NewRouteGuideClient(cli.ClientConn)
 
        result, err := client.GetFeature(context.Background(), 
&routeguide.Point{Latitude: 409146138, Longitude: -746188906})
        require.NoError(t, err)
diff --git a/protocol/grpc/grpc_invoker.go b/protocol/grpc/grpc_invoker.go
index 2b4ea43c4..5e53c82bd 100644
--- a/protocol/grpc/grpc_invoker.go
+++ b/protocol/grpc/grpc_invoker.go
@@ -19,6 +19,7 @@ package grpc
 
 import (
        "context"
+       "fmt"
        "reflect"
        "sync"
 )
@@ -40,6 +41,7 @@ import (
 )
 
 var errNoReply = errors.New("request need @response")
+var errNoInvoker = errors.New("grpc client invoker is not initialized")
 
 // GrpcInvoker is a gRPC invoker wrapping a generated client and guarding its 
lifecycle.
 type GrpcInvoker struct {
@@ -98,8 +100,18 @@ func (gi *GrpcInvoker) Invoke(ctx context.Context, 
invocation base.Invocation) r
        in = append(in, reflect.ValueOf(ctx))
        in = append(in, invocation.ParameterValues()...)
 
+       if !client.invoker.IsValid() {
+               result.SetError(errNoInvoker)
+               return &result
+       }
+
        methodName := invocation.MethodName()
        method := client.invoker.MethodByName(methodName)
+       if !method.IsValid() {
+               result.SetError(fmt.Errorf("grpc method %s not found on 
invoker", methodName))
+               return &result
+       }
+
        res := method.Call(in)
 
        result.SetResult(res[0])
diff --git a/protocol/grpc/grpc_invoker_test.go 
b/protocol/grpc/grpc_invoker_test.go
index 9245b76ae..cb961ebb6 100644
--- a/protocol/grpc/grpc_invoker_test.go
+++ b/protocol/grpc/grpc_invoker_test.go
@@ -60,6 +60,7 @@ func TestUnaryInvoke(t *testing.T) {
 
        cli, err := NewClient(url)
        require.NoError(t, err)
+       cli.invoker = 
reflect.ValueOf(helloworld.NewGreeterClient(cli.ClientConn))
 
        var args []reflect.Value
        args = append(args, reflect.ValueOf(&helloworld.HelloRequest{Name: 
"request name"}))
@@ -88,6 +89,7 @@ func TestStreamInvoke(t *testing.T) {
 
        cli, err := NewClient(url)
        require.NoError(t, err)
+       cli.invoker = 
reflect.ValueOf(routeguide.NewRouteGuideClient(cli.ClientConn))
 
        invoker := NewGrpcInvoker(url, cli)
 
diff --git a/protocol/grpc/internal/helloworld/client.go 
b/protocol/grpc/internal/helloworld/client.go
index 444424d06..8c13e638d 100644
--- a/protocol/grpc/internal/helloworld/client.go
+++ b/protocol/grpc/internal/helloworld/client.go
@@ -25,15 +25,6 @@ import (
        "google.golang.org/grpc"
 )
 
-import (
-       "dubbo.apache.org/dubbo-go/v3/config"
-)
-
-func init() {
-       
config.SetConsumerServiceByInterfaceName("io.grpc.examples.helloworld.GreeterGrpc$IGreeter",
 &GrpcGreeterImpl{})
-       config.SetConsumerService(&GrpcGreeterImpl{})
-}
-
 // GrpcGreeterImpl
 // used for dubbo-grpc biz client
 type GrpcGreeterImpl struct {
diff --git a/protocol/grpc/internal/routeguide/client.go 
b/protocol/grpc/internal/routeguide/client.go
index fd0a3b555..77bccd125 100644
--- a/protocol/grpc/internal/routeguide/client.go
+++ b/protocol/grpc/internal/routeguide/client.go
@@ -27,15 +27,6 @@ import (
        log "github.com/dubbogo/gost/log/logger"
 )
 
-import (
-       "dubbo.apache.org/dubbo-go/v3/config"
-)
-
-func init() {
-       
config.SetConsumerServiceByInterfaceName("io.grpc.examples.helloworld.GreeterGrpc$RouteGuide",
 &RouteGuideClientImpl{})
-       config.SetConsumerService(&RouteGuideClientImpl{})
-}
-
 // PrintFeatures lists all the features within the given bounding Rectangle.
 func PrintFeatures(stream RouteGuide_ListFeaturesClient) {
        for {

Reply via email to