This is an automated email from the ASF dual-hosted git repository.
xuetaoli 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 99fed3d3a refactor: remove config package dependency from application
generator (#3239)
99fed3d3a is described below
commit 99fed3d3a12780cac52a3a56281a7ec381a0c82d
Author: zbchi <[email protected]>
AuthorDate: Wed Mar 11 19:00:42 2026 +0800
refactor: remove config package dependency from application generator
(#3239)
* refactor: remove config package dependency from application generator
* format code
* fix blank line
---
.../cmd/testGenCode/template/newApp/cmd/app.go | 25 ++++++++--
.../testGenCode/template/newApp/conf/dubbogo.yaml | 28 -----------
.../template/newApp/pkg/service/service.go | 5 --
tools/dubbogo-cli/generator/application/cmd.go | 25 ++++++++--
tools/dubbogo-cli/generator/application/conf.go | 58 ----------------------
tools/dubbogo-cli/generator/application/pkg.go | 6 +--
6 files changed, 41 insertions(+), 106 deletions(-)
diff --git a/tools/dubbogo-cli/cmd/testGenCode/template/newApp/cmd/app.go
b/tools/dubbogo-cli/cmd/testGenCode/template/newApp/cmd/app.go
index 9d0674950..4380af882 100644
--- a/tools/dubbogo-cli/cmd/testGenCode/template/newApp/cmd/app.go
+++ b/tools/dubbogo-cli/cmd/testGenCode/template/newApp/cmd/app.go
@@ -18,18 +18,33 @@
package main
import (
- _ "dubbo-go-app/pkg/service"
+ "dubbo-go-app/api"
+
+ "dubbo-go-app/pkg/service"
)
import (
- "dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
)
-// export DUBBO_GO_CONFIG_PATH=$PATH_TO_APP/conf/dubbogo.yaml
func main() {
- if err := config.Load(); err != nil {
+ srv, err := server.NewServer(
+ server.WithServerProtocol(
+ protocol.WithPort(20000),
+ protocol.WithTriple(),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ if err := api.RegisterGreeterServer(srv, &service.GreeterServerImpl{});
err != nil {
+ panic(err)
+ }
+
+ if err := srv.Serve(); err != nil {
panic(err)
}
- select {}
}
diff --git
a/tools/dubbogo-cli/cmd/testGenCode/template/newApp/conf/dubbogo.yaml
b/tools/dubbogo-cli/cmd/testGenCode/template/newApp/conf/dubbogo.yaml
deleted file mode 100644
index e8d948078..000000000
--- a/tools/dubbogo-cli/cmd/testGenCode/template/newApp/conf/dubbogo.yaml
+++ /dev/null
@@ -1,28 +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.
-
-dubbo:
- registries:
- nacos:
- protocol: nacos
- address: nacos:8848
- protocols:
- triple:
- name: tri
- port: 20000
- provider:
- services:
- GreeterServerImpl:
- interface: "" # read from stub
diff --git
a/tools/dubbogo-cli/cmd/testGenCode/template/newApp/pkg/service/service.go
b/tools/dubbogo-cli/cmd/testGenCode/template/newApp/pkg/service/service.go
index 4529ffc90..93c386e92 100644
--- a/tools/dubbogo-cli/cmd/testGenCode/template/newApp/pkg/service/service.go
+++ b/tools/dubbogo-cli/cmd/testGenCode/template/newApp/pkg/service/service.go
@@ -27,7 +27,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
- "dubbo.apache.org/dubbo-go/v3/config"
)
type GreeterServerImpl struct {
@@ -38,7 +37,3 @@ func (s *GreeterServerImpl) SayHello(ctx context.Context, in
*api.HelloRequest)
logger.Infof("Dubbo-go GreeterProvider get user name = %s\n", in.Name)
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
}
-
-func init() {
- config.SetProviderService(&GreeterServerImpl{})
-}
diff --git a/tools/dubbogo-cli/generator/application/cmd.go
b/tools/dubbogo-cli/generator/application/cmd.go
index 140d01875..050333598 100644
--- a/tools/dubbogo-cli/generator/application/cmd.go
+++ b/tools/dubbogo-cli/generator/application/cmd.go
@@ -38,20 +38,35 @@ const (
package main
import (
- _ "dubbo-go-app/pkg/service"
+ "dubbo-go-app/api"
+
+ "dubbo-go-app/pkg/service"
)
import (
- "dubbo.apache.org/dubbo-go/v3/config"
+ "dubbo.apache.org/dubbo-go/v3/protocol"
+ "dubbo.apache.org/dubbo-go/v3/server"
_ "dubbo.apache.org/dubbo-go/v3/imports"
)
-// export DUBBO_GO_CONFIG_PATH=$PATH_TO_APP/conf/dubbogo.yaml
func main() {
- if err := config.Load(); err != nil {
+ srv, err := server.NewServer(
+ server.WithServerProtocol(
+ protocol.WithPort(20000),
+ protocol.WithTriple(),
+ ),
+ )
+ if err != nil {
+ panic(err)
+ }
+
+ if err := api.RegisterGreeterServer(srv, &service.GreeterServerImpl{});
err != nil {
+ panic(err)
+ }
+
+ if err := srv.Serve(); err != nil {
panic(err)
}
- select {}
}
`
diff --git a/tools/dubbogo-cli/generator/application/conf.go
b/tools/dubbogo-cli/generator/application/conf.go
deleted file mode 100644
index da735d1b4..000000000
--- a/tools/dubbogo-cli/generator/application/conf.go
+++ /dev/null
@@ -1,58 +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 application
-
-const (
- configFile = `# 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.
-
-dubbo:
- registries:
- nacos:
- protocol: nacos
- address: nacos:8848
- protocols:
- triple:
- name: tri
- port: 20000
- provider:
- services:
- GreeterServerImpl:
- interface: "" # read from stub
-`
-)
-
-func init() {
- fileMap["configFile"] = &fileGenerator{
- path: "./conf",
- file: "dubbogo.yaml",
- context: configFile,
- }
-}
diff --git a/tools/dubbogo-cli/generator/application/pkg.go
b/tools/dubbogo-cli/generator/application/pkg.go
index 269931c01..97243023e 100644
--- a/tools/dubbogo-cli/generator/application/pkg.go
+++ b/tools/dubbogo-cli/generator/application/pkg.go
@@ -47,7 +47,6 @@ import (
import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
- "dubbo.apache.org/dubbo-go/v3/config"
)
type GreeterServerImpl struct {
@@ -58,10 +57,7 @@ func (s *GreeterServerImpl) SayHello(ctx context.Context, in
*api.HelloRequest)
logger.Infof("Dubbo-go GreeterProvider get user name = %s\n", in.Name)
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
}
-
-func init() {
- config.SetProviderService(&GreeterServerImpl{})
-}`
+`
)
func init() {