Skip to content

Commit

Permalink
Improve example
Browse files Browse the repository at this point in the history
  • Loading branch information
MIBc committed Apr 20, 2022
1 parent bd7b966 commit d7e627a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ polaris/
.idea/
.vscode/
examples/quickstart/consumer/client
examples/quickstart/provider/server
examples/quickstart/provider/server
vendor
2 changes: 1 addition & 1 deletion examples/circuitbreak/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func main() {
}
go func() {
c := make(chan os.Signal)
signal.Notify(c)
signal.Notify(c, os.Interrupt)
s := <-c
log.Printf("receive quit signal: %v", s)
// 执行北极星的反注册命令
Expand Down
2 changes: 1 addition & 1 deletion examples/circuitbreak/provider/polaris.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global:
serverConnector:
addresses:
- 9.134.15.118:8091
- 9.134.15.118:8091
6 changes: 4 additions & 2 deletions examples/quickstart/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ const (
)

func main() {
// grpc客户端连接获取
address := fmt.Sprintf("0.0.0.0:%d", listenPort)
// grpc客户端连接获
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
conn, err := grpc.DialContext(ctx, "polaris://QuickStartEchoServerGRPC/", grpc.WithInsecure())
Expand Down Expand Up @@ -69,7 +70,8 @@ func main() {
_, _ = w.Write([]byte(resp.GetValue()))
}
http.HandleFunc("/echo", indexHandler)
if err := http.ListenAndServe(fmt.Sprintf(":%d", listenPort), nil); nil != err {
log.Printf("Consumer is running at %s", address)
if err := http.ListenAndServe(address, nil); nil != err {
log.Fatal(err)
}

Expand Down
7 changes: 4 additions & 3 deletions examples/quickstart/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import (
"os"
"os/signal"

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

"google.golang.org/grpc"

polaris "github.com/polarismesh/grpc-go-polaris"
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
)

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

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

Expand All @@ -59,13 +59,14 @@ func main() {
}
go func() {
c := make(chan os.Signal)
signal.Notify(c)
signal.Notify(c, os.Interrupt)
s := <-c
log.Printf("receive quit signal: %v", s)
// 执行北极星的反注册命令
pSrv.Deregister()
srv.GracefulStop()
}()
log.Printf("Provider is running at %s", address)
err = srv.Serve(listen)
if nil != err {
log.Printf("listen err: %v", err)
Expand Down
5 changes: 2 additions & 3 deletions examples/ratelimit/local/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import (
"os"
"os/signal"

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

"google.golang.org/grpc"

polaris "github.com/polarismesh/grpc-go-polaris"
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
)

Expand Down Expand Up @@ -64,7 +63,7 @@ func main() {
}
go func() {
c := make(chan os.Signal)
signal.Notify(c)
signal.Notify(c, os.Interrupt)
s := <-c
log.Printf("receive quit signal: %v", s)
// 执行北极星的反注册命令
Expand Down
7 changes: 3 additions & 4 deletions examples/routing/version/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ import (
"os"
"os/signal"

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

"google.golang.org/grpc"

polaris "github.com/polarismesh/grpc-go-polaris"
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
)

Expand All @@ -39,7 +38,7 @@ var (
)

func initArgs() {
flag.StringVar(&version, "version", "", "eg. 1.0.0")
flag.StringVar(&version, "version", "1.0.0", "eg. 1.0.0")
}

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

0 comments on commit d7e627a

Please sign in to comment.