Skip to content

Commit 22baaab

Browse files
committed
Improve example
1 parent 14ee062 commit 22baaab

File tree

7 files changed

+22
-16
lines changed

7 files changed

+22
-16
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"net"
2525
"os"
2626
"os/signal"
27+
"syscall"
2728

2829
polaris "github.com/polarismesh/grpc-go-polaris"
2930

@@ -65,7 +66,7 @@ func main() {
6566
}
6667
go func() {
6768
c := make(chan os.Signal)
68-
signal.Notify(c)
69+
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
6970
s := <-c
7071
log.Printf("receive quit signal: %v", s)
7172
// 执行北极星的反注册命令
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+
- 9.134.15.118:8091

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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424
"net"
2525
"os"
2626
"os/signal"
27-
28-
polaris "github.com/polarismesh/grpc-go-polaris"
27+
"syscall"
2928

3029
"google.golang.org/grpc"
3130

31+
polaris "github.com/polarismesh/grpc-go-polaris"
3232
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
3333
)
3434

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

4242
// Echo gRPC testing method
4343
func (h *EchoQuickStartService) Echo(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {
44+
log.Printf("Ehco is called")
4445
return &pb.EchoResponse{Value: "echo: " + req.Value}, nil
4546
}
4647

@@ -53,19 +54,20 @@ func main() {
5354
log.Fatalf("Failed to addr %s: %v", address, err)
5455
}
5556
// 执行北极星的注册命令
56-
pSrv, err := polaris.Register(srv, listen, polaris.WithServerApplication("QuickStartEchoServerGRPC"))
57+
pSrv, err := polaris.Register(srv, listen, polaris.WithServerApplication("QuickStartEchoServerGRPC222"))
5758
if nil != err {
5859
log.Fatal(err)
5960
}
6061
go func() {
6162
c := make(chan os.Signal)
62-
signal.Notify(c)
63+
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
6364
s := <-c
6465
log.Printf("receive quit signal: %v", s)
6566
// 执行北极星的反注册命令
6667
pSrv.Deregister()
6768
srv.GracefulStop()
6869
}()
70+
log.Printf("Provider is running at %s", address)
6971
err = srv.Serve(listen)
7072
if nil != err {
7173
log.Printf("listen err: %v", err)

examples/ratelimit/local/provider/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ import (
2424
"net"
2525
"os"
2626
"os/signal"
27-
28-
polaris "github.com/polarismesh/grpc-go-polaris"
27+
"syscall"
2928

3029
"google.golang.org/grpc"
3130

31+
polaris "github.com/polarismesh/grpc-go-polaris"
3232
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
3333
)
3434

@@ -64,7 +64,7 @@ func main() {
6464
}
6565
go func() {
6666
c := make(chan os.Signal)
67-
signal.Notify(c)
67+
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
6868
s := <-c
6969
log.Printf("receive quit signal: %v", s)
7070
// 执行北极星的反注册命令

examples/routing/version/provider/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import (
2525
"net"
2626
"os"
2727
"os/signal"
28-
29-
polaris "github.com/polarismesh/grpc-go-polaris"
28+
"syscall"
3029

3130
"google.golang.org/grpc"
3231

32+
polaris "github.com/polarismesh/grpc-go-polaris"
3333
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
3434
)
3535

@@ -39,7 +39,7 @@ var (
3939
)
4040

4141
func initArgs() {
42-
flag.StringVar(&version, "version", "", "eg. 1.0.0")
42+
flag.StringVar(&version, "version", "1.0.0", "eg. 1.0.0")
4343
}
4444

4545
// EchoCircuitBreakerService gRPC echo service struct
@@ -73,7 +73,7 @@ func main() {
7373
}
7474
go func() {
7575
c := make(chan os.Signal)
76-
signal.Notify(c)
76+
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
7777
s := <-c
7878
log.Printf("receive quit signal: %v", s)
7979
// 执行北极星的反注册命令

0 commit comments

Comments
 (0)