Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions tools/dubbogo-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,11 @@ The Demo uses the direct connection mode, without relying on the registration ce
│   ├── samples_api.proto
│   └── samples_api_triple.pb.go
├── go-client
│   ├── cmd
│   │   └── client.go
│   └── conf
│   └── dubbogo.yaml
│   └── cmd
│   └── client.go
├── go-server
│   ├── cmd
│   │   └── server.go
│   └── conf
│   └── dubbogo.yaml
│   └── cmd
│   └── server.go
└── go.mod
```

Expand Down
12 changes: 4 additions & 8 deletions tools/dubbogo-cli/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,11 @@ dubbogo-cli newDemo .
│   ├── samples_api.proto
│   └── samples_api_triple.pb.go
├── go-client
│   ├── cmd
│   │   └── client.go
│   └── conf
│   └── dubbogo.yaml
│   └── cmd
│   └── client.go
├── go-server
│   ├── cmd
│   │   └── server.go
│   └── conf
│   └── dubbogo.yaml
│   └── cmd
│   └── server.go
└── go.mod
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,29 @@ import (
)

import (
"dubbo.apache.org/dubbo-go/v3/client"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"
)

var grpcGreeterImpl = new(api.GreeterClientImpl)

// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yaml
func main() {
config.SetConsumerService(grpcGreeterImpl)
if err := config.Load(); err != nil {
cli, err := client.NewClient(
client.WithClientURL("tri://localhost:20000"),
)
if err != nil {
panic(err)
}

greeterClient, err := api.NewGreeterClient(cli)
if err != nil {
panic(err)
}

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Name: "laurence",
}
reply, err := grpcGreeterImpl.SayHello(context.Background(), req)
reply, err := greeterClient.SayHello(context.Background(), req)
if err != nil {
logger.Error(err)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (

import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
"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"
)

type GreeterProvider struct {
Expand All @@ -40,11 +41,22 @@ func (s *GreeterProvider) SayHello(ctx context.Context, in *api.HelloRequest) (*
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
}

// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-server/conf/dubbogo.yaml
func main() {
config.SetProviderService(&GreeterProvider{})
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, &GreeterProvider{}); err != nil {
panic(err)
}

if err := srv.Serve(); err != nil {
panic(err)
}
select {}
}

This file was deleted.

5 changes: 3 additions & 2 deletions tools/dubbogo-cli/generator/sample/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions tools/dubbogo-cli/generator/sample/api_tripe.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 7 additions & 3 deletions tools/dubbogo-cli/generator/sample/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@

package sample

import (
"strings"
)

const (
license = `/*
* Licensed to the Apache Software Foundation (ASF) under one or more
Expand All @@ -33,7 +37,7 @@ const (
* 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.
*/

`
*/`
)

var licenseForTemplates = strings.TrimSuffix(license, " \n")
16 changes: 9 additions & 7 deletions tools/dubbogo-cli/generator/sample/gen_c_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ dubbo:
interface: "" # read from pb`
)

func init() {
fileMap["clientConfigFile"] = &fileGenerator{
path: "./go-client/conf",
file: "dubbogo.yaml",
context: clientConfigFile,
}
}
// Config files are no longer needed in the new config-free pattern
// The client now uses programmatic configuration via client.NewClient()
// func init() {
// fileMap["clientConfigFile"] = &fileGenerator{
// path: "./go-client/conf",
// file: "dubbogo.yaml",
// context: clientConfigFile,
// }
// }
23 changes: 14 additions & 9 deletions tools/dubbogo-cli/generator/sample/gen_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package sample

const (
clientCode = `package main
clientCode = `
package main

import (
"context"
Expand All @@ -29,25 +30,29 @@ import (
)

import (
"dubbo.apache.org/dubbo-go/v3/client"
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"
)

var grpcGreeterImpl = new(api.GreeterClientImpl)

// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yaml
func main() {
config.SetConsumerService(grpcGreeterImpl)
if err := config.Load(); err != nil {
cli, err := client.NewClient(
client.WithClientURL("tri://localhost:20000"),
)
if err != nil {
panic(err)
}

greeterClient, err := api.NewGreeterClient(cli)
if err != nil {
panic(err)
}

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Name: "laurence",
}
reply, err := grpcGreeterImpl.SayHello(context.Background(), req)
reply, err := greeterClient.SayHello(context.Background(), req)
if err != nil {
logger.Error(err)
}
Expand All @@ -60,6 +65,6 @@ func init() {
fileMap["clientGenerator"] = &fileGenerator{
path: "./go-client/cmd",
file: "client.go",
context: license + clientCode,
context: licenseForTemplates + "\n" + clientCode,
}
}
16 changes: 9 additions & 7 deletions tools/dubbogo-cli/generator/sample/gen_s_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ dubbo:
interface: "" # read from pb`
)

func init() {
fileMap["srvConfGenerator"] = &fileGenerator{
path: "./go-server/conf",
file: "dubbogo.yaml",
context: serverConfigFile,
}
}
// Config files are no longer needed in the new config-free pattern
// The server now uses programmatic configuration via server.NewServer()
// func init() {
// fileMap["srvConfGenerator"] = &fileGenerator{
// path: "./go-server/conf",
// file: "dubbogo.yaml",
// context: serverConfigFile,
// }
// }
27 changes: 20 additions & 7 deletions tools/dubbogo-cli/generator/sample/gen_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package sample

const (
serverCode = `package main
serverCode = `
package main

import (
"context"
Expand All @@ -30,7 +31,8 @@ import (

import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
"dubbo.apache.org/dubbo-go/v3/server"
"dubbo.apache.org/dubbo-go/v3/protocol"
_ "dubbo.apache.org/dubbo-go/v3/imports"
)

Expand All @@ -43,13 +45,24 @@ func (s *GreeterProvider) SayHello(ctx context.Context, in *api.HelloRequest) (*
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
}

// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-server/conf/dubbogo.yaml
func main() {
config.SetProviderService(&GreeterProvider{})
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, &GreeterProvider{}); err != nil {
panic(err)
}

if err := srv.Serve(); err != nil {
panic(err)
}
select {}
}
`
)
Expand All @@ -58,7 +71,7 @@ func init() {
fileMap["srvGenerator"] = &fileGenerator{
path: "./go-server/cmd",
file: "server.go",
context: license + serverCode,
context: licenseForTemplates + "\n" + serverCode,
}
//var str = "`" + `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + "`"
}
5 changes: 3 additions & 2 deletions tools/dubbogo-cli/generator/sample/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
package sample

const (
protoFile = `syntax = "proto3";
protoFile = `
syntax = "proto3";
package api;

option go_package = "./;api";
Expand Down Expand Up @@ -48,6 +49,6 @@ func init() {
fileMap[protoFile] = &fileGenerator{
path: "./api",
file: "samples_api.proto",
context: license + protoFile,
context: license + "\n" + protoFile,
}
}
Loading