Skip to content

Commit 5010280

Browse files
committed
Improve example
1 parent bd7b966 commit 5010280

File tree

7 files changed

+17
-15
lines changed

7 files changed

+17
-15
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ polaris/
22
.idea/
33
.vscode/
44
examples/quickstart/consumer/client
5-
examples/quickstart/provider/server
5+
examples/quickstart/provider/server
6+
vendor

examples/circuitbreak/provider/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func main() {
6565
}
6666
go func() {
6767
c := make(chan os.Signal)
68-
signal.Notify(c)
68+
signal.Notify(c, os.Interrupt)
6969
s := <-c
7070
log.Printf("receive quit signal: %v", s)
7171
// 执行北极星的反注册命令
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
global:
22
serverConnector:
33
addresses:
4-
- 9.134.15.118:8091
4+
- 172.24.213.187:32022

examples/quickstart/consumer/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const (
3434
)
3535

3636
func main() {
37-
// grpc客户端连接获取
37+
address := fmt.Sprintf("0.0.0.0:%d", listenPort)
38+
// grpc客户端连接获
3839
ctx, cancel := context.WithCancel(context.Background())
3940
defer cancel()
4041
conn, err := grpc.DialContext(ctx, "polaris://QuickStartEchoServerGRPC/", grpc.WithInsecure())
@@ -69,7 +70,8 @@ func main() {
6970
_, _ = w.Write([]byte(resp.GetValue()))
7071
}
7172
http.HandleFunc("/echo", indexHandler)
72-
if err := http.ListenAndServe(fmt.Sprintf(":%d", listenPort), nil); nil != err {
73+
log.Printf("Consumer is running at %s", address)
74+
if err := http.ListenAndServe(address, nil); nil != err {
7375
log.Fatal(err)
7476
}
7577

examples/quickstart/provider/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import (
2525
"os"
2626
"os/signal"
2727

28-
polaris "github.com/polarismesh/grpc-go-polaris"
29-
3028
"google.golang.org/grpc"
3129

30+
polaris "github.com/polarismesh/grpc-go-polaris"
3231
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
3332
)
3433

@@ -41,6 +40,7 @@ type EchoQuickStartService struct{}
4140

4241
// Echo gRPC testing method
4342
func (h *EchoQuickStartService) Echo(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {
43+
log.Printf("Ehco is called")
4444
return &pb.EchoResponse{Value: "echo: " + req.Value}, nil
4545
}
4646

@@ -59,13 +59,14 @@ func main() {
5959
}
6060
go func() {
6161
c := make(chan os.Signal)
62-
signal.Notify(c)
62+
signal.Notify(c, os.Interrupt)
6363
s := <-c
6464
log.Printf("receive quit signal: %v", s)
6565
// 执行北极星的反注册命令
6666
pSrv.Deregister()
6767
srv.GracefulStop()
6868
}()
69+
log.Printf("Provider is running at %s", address)
6970
err = srv.Serve(listen)
7071
if nil != err {
7172
log.Printf("listen err: %v", err)

examples/ratelimit/local/provider/main.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import (
2525
"os"
2626
"os/signal"
2727

28-
polaris "github.com/polarismesh/grpc-go-polaris"
29-
3028
"google.golang.org/grpc"
3129

30+
polaris "github.com/polarismesh/grpc-go-polaris"
3231
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
3332
)
3433

@@ -64,7 +63,7 @@ func main() {
6463
}
6564
go func() {
6665
c := make(chan os.Signal)
67-
signal.Notify(c)
66+
signal.Notify(c, os.Interrupt)
6867
s := <-c
6968
log.Printf("receive quit signal: %v", s)
7069
// 执行北极星的反注册命令

examples/routing/version/provider/main.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ import (
2626
"os"
2727
"os/signal"
2828

29-
polaris "github.com/polarismesh/grpc-go-polaris"
30-
3129
"google.golang.org/grpc"
3230

31+
polaris "github.com/polarismesh/grpc-go-polaris"
3332
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
3433
)
3534

@@ -39,7 +38,7 @@ var (
3938
)
4039

4140
func initArgs() {
42-
flag.StringVar(&version, "version", "", "eg. 1.0.0")
41+
flag.StringVar(&version, "version", "1.0.0", "eg. 1.0.0")
4342
}
4443

4544
// EchoCircuitBreakerService gRPC echo service struct
@@ -73,7 +72,7 @@ func main() {
7372
}
7473
go func() {
7574
c := make(chan os.Signal)
76-
signal.Notify(c)
75+
signal.Notify(c, os.Interrupt)
7776
s := <-c
7877
log.Printf("receive quit signal: %v", s)
7978
// 执行北极星的反注册命令

0 commit comments

Comments
 (0)