Skip to content

Commit 99fed3d

Browse files
authored
refactor: remove config package dependency from application generator (#3239)
* refactor: remove config package dependency from application generator * format code * fix blank line
1 parent 9d59133 commit 99fed3d

File tree

6 files changed

+41
-106
lines changed

6 files changed

+41
-106
lines changed

tools/dubbogo-cli/cmd/testGenCode/template/newApp/cmd/app.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,33 @@
1818
package main
1919

2020
import (
21-
_ "dubbo-go-app/pkg/service"
21+
"dubbo-go-app/api"
22+
23+
"dubbo-go-app/pkg/service"
2224
)
2325

2426
import (
25-
"dubbo.apache.org/dubbo-go/v3/config"
2627
_ "dubbo.apache.org/dubbo-go/v3/imports"
28+
"dubbo.apache.org/dubbo-go/v3/protocol"
29+
"dubbo.apache.org/dubbo-go/v3/server"
2730
)
2831

29-
// export DUBBO_GO_CONFIG_PATH=$PATH_TO_APP/conf/dubbogo.yaml
3032
func main() {
31-
if err := config.Load(); err != nil {
33+
srv, err := server.NewServer(
34+
server.WithServerProtocol(
35+
protocol.WithPort(20000),
36+
protocol.WithTriple(),
37+
),
38+
)
39+
if err != nil {
40+
panic(err)
41+
}
42+
43+
if err := api.RegisterGreeterServer(srv, &service.GreeterServerImpl{}); err != nil {
44+
panic(err)
45+
}
46+
47+
if err := srv.Serve(); err != nil {
3248
panic(err)
3349
}
34-
select {}
3550
}

tools/dubbogo-cli/cmd/testGenCode/template/newApp/conf/dubbogo.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

tools/dubbogo-cli/cmd/testGenCode/template/newApp/pkg/service/service.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import (
2727

2828
import (
2929
"dubbo.apache.org/dubbo-go/v3/common/logger"
30-
"dubbo.apache.org/dubbo-go/v3/config"
3130
)
3231

3332
type GreeterServerImpl struct {
@@ -38,7 +37,3 @@ func (s *GreeterServerImpl) SayHello(ctx context.Context, in *api.HelloRequest)
3837
logger.Infof("Dubbo-go GreeterProvider get user name = %s\n", in.Name)
3938
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
4039
}
41-
42-
func init() {
43-
config.SetProviderService(&GreeterServerImpl{})
44-
}

tools/dubbogo-cli/generator/application/cmd.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,35 @@ const (
3838
package main
3939
4040
import (
41-
_ "dubbo-go-app/pkg/service"
41+
"dubbo-go-app/api"
42+
43+
"dubbo-go-app/pkg/service"
4244
)
4345
4446
import (
45-
"dubbo.apache.org/dubbo-go/v3/config"
47+
"dubbo.apache.org/dubbo-go/v3/protocol"
48+
"dubbo.apache.org/dubbo-go/v3/server"
4649
_ "dubbo.apache.org/dubbo-go/v3/imports"
4750
)
4851
49-
// export DUBBO_GO_CONFIG_PATH=$PATH_TO_APP/conf/dubbogo.yaml
5052
func main() {
51-
if err := config.Load(); err != nil {
53+
srv, err := server.NewServer(
54+
server.WithServerProtocol(
55+
protocol.WithPort(20000),
56+
protocol.WithTriple(),
57+
),
58+
)
59+
if err != nil {
60+
panic(err)
61+
}
62+
63+
if err := api.RegisterGreeterServer(srv, &service.GreeterServerImpl{}); err != nil {
64+
panic(err)
65+
}
66+
67+
if err := srv.Serve(); err != nil {
5268
panic(err)
5369
}
54-
select {}
5570
}
5671
5772
`

tools/dubbogo-cli/generator/application/conf.go

Lines changed: 0 additions & 58 deletions
This file was deleted.

tools/dubbogo-cli/generator/application/pkg.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
4848
import (
4949
"dubbo.apache.org/dubbo-go/v3/common/logger"
50-
"dubbo.apache.org/dubbo-go/v3/config"
5150
)
5251
5352
type GreeterServerImpl struct {
@@ -58,10 +57,7 @@ func (s *GreeterServerImpl) SayHello(ctx context.Context, in *api.HelloRequest)
5857
logger.Infof("Dubbo-go GreeterProvider get user name = %s\n", in.Name)
5958
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
6059
}
61-
62-
func init() {
63-
config.SetProviderService(&GreeterServerImpl{})
64-
}`
60+
`
6561
)
6662

6763
func init() {

0 commit comments

Comments
 (0)