Skip to content
Open
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
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
3 changes: 2 additions & 1 deletion examples/circuitbreak/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"net"
"os"
"os/signal"
"syscall"

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

Expand Down Expand Up @@ -65,7 +66,7 @@ func main() {
}
go func() {
c := make(chan os.Signal)
signal.Notify(c)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
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
10 changes: 6 additions & 4 deletions examples/quickstart/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"net"
"os"
"os/signal"

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

"google.golang.org/grpc"

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

Expand All @@ -41,6 +41,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 @@ -53,19 +54,20 @@ func main() {
log.Fatalf("Failed to addr %s: %v", address, err)
}
// 执行北极星的注册命令
pSrv, err := polaris.Register(srv, listen, polaris.WithServerApplication("QuickStartEchoServerGRPC"))
pSrv, err := polaris.Register(srv, listen, polaris.WithServerApplication("QuickStartEchoServerGRPC222"))
if nil != err {
log.Fatal(err)
}
go func() {
c := make(chan os.Signal)
signal.Notify(c)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
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
6 changes: 3 additions & 3 deletions examples/ratelimit/local/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"net"
"os"
"os/signal"

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

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

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

"google.golang.org/grpc"

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

Expand All @@ -39,7 +39,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 +73,7 @@ func main() {
}
go func() {
c := make(chan os.Signal)
signal.Notify(c)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
s := <-c
log.Printf("receive quit signal: %v", s)
// 执行北极星的反注册命令
Expand Down