Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor:重构grpc-go-polaris的相关版本设计 #63

Merged
merged 25 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
362cf49
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 9, 2023
e8582a5
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
4e69a11
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
67cc328
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
2a0778f
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
e4a0fc1
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
4b8f4af
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
bbc1b00
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
79358a8
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
1a554e9
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
edc40ae
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
9565db4
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 10, 2023
e6f1cee
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 11, 2023
dbe4143
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 11, 2023
a8095f3
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 11, 2023
40cbf63
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 12, 2023
3bc5148
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 12, 2023
706f99d
refactor:优化grpc-go-polaris相关实现
chuntaojun Jan 12, 2023
8fc96c7
docs:readme refactor
chuntaojun Jan 14, 2023
1a6227d
refactor:重构grpc-go-polaris的相关版本设计
chuntaojun Jun 20, 2024
3a615f1
refactor:重构grpc-go-polaris的相关版本设计
chuntaojun Jun 20, 2024
28b1777
refactor:重构grpc-go-polaris的相关版本设计
chuntaojun Jun 20, 2024
7aa81a4
refactor:重构grpc-go-polaris的相关版本设计
chuntaojun Jun 20, 2024
60c3b56
refactor:重构grpc-go-polaris的相关版本设计
chuntaojun Jun 20, 2024
cea537f
refactor:重构grpc-go-polaris的相关版本设计
chuntaojun Jun 21, 2024
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
6 changes: 0 additions & 6 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ func DialContext(ctx context.Context, target string, opts ...DialOption) (conn *
if options.Config != nil {
setPolarisConfig(options.Config)
}
if options.SDKContext != nil {
setPolarisContext(options.SDKContext)
}

if !strings.HasPrefix(target, prefix) {
// not polaris target, go through gRPC resolver
Expand Down Expand Up @@ -80,9 +77,6 @@ func BuildTarget(target string, opts ...DialOption) (string, error) {
if options.Config != nil {
setPolarisConfig(options.Config)
}
if options.SDKContext != nil {
setPolarisContext(options.SDKContext)
}

endpoint := base64.URLEncoding.EncodeToString(jsonStr)
target = fmt.Sprintf(prefix+"%s?%s=%s", target, optionsKey, endpoint)
Expand Down
2 changes: 1 addition & 1 deletion client_option.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func WithPolarisConfig(polarisCfg config.Configuration) DialOption {
// WithPolarisContext set polaris SDKContext
func WithPolarisContext(sdkContext api.SDKContext) DialOption {
return newFuncDialOption(func(options *dialOptions) {
options.SDKContext = sdkContext
setPolarisContext(sdkContext)
})
}

Expand Down
2 changes: 1 addition & 1 deletion examples/circuitbreak/consumer/polaris.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global:
serverConnector:
addresses:
- 183.47.111.80:8091
- 127.0.0.1:8091
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:
- 183.47.111.80:8091
- 127.0.0.1:8091
21 changes: 11 additions & 10 deletions examples/quickstart/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package main

Check warning on line 18 in examples/quickstart/provider/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.18.x)

should have a package comment

Check warning on line 18 in examples/quickstart/provider/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.15.x)

should have a package comment

import (
"context"
Expand All @@ -24,8 +24,6 @@
"net"
"time"

"google.golang.org/grpc"

polaris "github.com/polarismesh/grpc-go-polaris"
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
)
Expand All @@ -40,28 +38,31 @@
}

// Echo gRPC testing method
func (h *EchoQuickStartService) Echo(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {

Check warning on line 41 in examples/quickstart/provider/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.15.x)

parameter 'ctx' seems to be unused, consider removing or renaming it as _
return &pb.EchoResponse{Value: fmt.Sprintf("echo: %s, port: %d", req.Value, h.actualPort)}, nil
}

func main() {
srv := grpc.NewServer()
address := fmt.Sprintf("0.0.0.0:%d", listenPort)
listen, err := net.Listen("tcp", address)
if err != nil {
log.Fatalf("Failed to addr %s: %v", address, err)
}
pb.RegisterEchoServerServer(srv, &EchoQuickStartService{

srv, err := polaris.NewServer(polaris.WithServiceName("QuickStartEchoServerGRPC"),
polaris.WithServerHost("127.0.0.1"),
polaris.WithDelayRegisterEnable(&polaris.WaitDelayStrategy{WaitTime: 10 * time.Second}),
polaris.WithGracefulStopEnable(10*time.Second))
if err != nil {
log.Fatalf("Failed to addr %s: %v", address, err)
}

pb.RegisterEchoServerServer(srv.Server, &EchoQuickStartService{
actualPort: listen.Addr().(*net.TCPAddr).Port,
})

// 启动服务
if err := polaris.Serve(srv, listen,
polaris.WithServiceName("QuickStartEchoServerGRPC"),
polaris.WithServerHost("127.0.0.1"),
polaris.WithDelayRegisterEnable(&polaris.WaitDelayStrategy{WaitTime: 10 * time.Second}),
polaris.WithGracefulStopEnable(10*time.Second),
); nil != err {
if err := srv.Serve(listen); nil != err {
log.Printf("listen err: %v", err)
}
}
23 changes: 13 additions & 10 deletions examples/ratelimit/provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* specific language governing permissions and limitations under the License.
*/

package main

Check warning on line 18 in examples/ratelimit/provider/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.18.x)

should have a package comment

Check warning on line 18 in examples/ratelimit/provider/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.16.x)

should have a package comment

import (
"context"
Expand All @@ -23,8 +23,6 @@
"log"
"net"

"google.golang.org/grpc"

polaris "github.com/polarismesh/grpc-go-polaris"
"github.com/polarismesh/grpc-go-polaris/examples/common/pb"
)
Expand All @@ -38,7 +36,7 @@
}

// Echo gRPC testing method
func (h *EchoRateLimitService) Echo(ctx context.Context, req *pb.EchoRequest) (*pb.EchoResponse, error) {

Check warning on line 39 in examples/ratelimit/provider/main.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.16.x)

parameter 'ctx' seems to be unused, consider removing or renaming it as _
return &pb.EchoResponse{Value: fmt.Sprintf("echo: %s", req.Value)}, nil
}

Expand All @@ -48,15 +46,20 @@
if err != nil {
log.Fatalf("Failed to addr %s: %v", address, err)
}
listenAddr := listen.Addr().String()
fmt.Printf("listen address is %s\n", listenAddr)
interceptor := polaris.NewRateLimitInterceptor().WithServiceName("RateLimitEchoServerGRPC")
srv := grpc.NewServer(grpc.UnaryInterceptor(interceptor.UnaryInterceptor))
pb.RegisterEchoServerServer(srv, &EchoRateLimitService{})

srv, err := polaris.NewServer(polaris.WithServiceName("RateLimitEchoServerGRPC"),
polaris.WithServerHost("127.0.0.1"),
// 开启限流能力
polaris.WithPolarisRateLimit(),
)
if err != nil {
log.Fatalf("Failed to addr %s: %v", address, err)
}

pb.RegisterEchoServerServer(srv.Server, &EchoRateLimitService{})

// 启动服务
if err := polaris.Serve(srv, listen,
polaris.WithServiceName("RateLimitEchoServerGRPC"),
); nil != err {
if err := srv.Serve(listen); nil != err {
log.Printf("listen err: %v", err)
}
}
2 changes: 1 addition & 1 deletion examples/ratelimit/provider/polaris.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global:
serverConnector:
addresses:
- 127.0.0.1:8091
- 127.0.0.1:8091
2 changes: 1 addition & 1 deletion examples/routing/consumer/polaris.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global:
serverConnector:
addresses:
- 183.47.111.80:8091
- 127.0.0.1:8091
2 changes: 1 addition & 1 deletion examples/routing/provider/polaris.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
global:
serverConnector:
addresses:
- 183.47.111.80:8091
- 127.0.0.1:8091
27 changes: 14 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ module github.com/polarismesh/grpc-go-polaris
go 1.15

require (
github.com/dlclark/regexp2 v1.10.0 // indirect
github.com/golang/protobuf v1.5.3
github.com/google/uuid v1.3.0
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/dlclark/regexp2 v1.11.0 // indirect
github.com/golang/protobuf v1.5.4
github.com/google/uuid v1.6.0
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/polarismesh/polaris-go v1.5.2
github.com/polarismesh/specification v1.3.2
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/common v0.44.0 // indirect
github.com/prometheus/procfs v0.11.1 // indirect
github.com/polarismesh/polaris-go v1.5.6
github.com/polarismesh/specification v1.5.1
github.com/prometheus/client_golang v1.19.1 // indirect
github.com/prometheus/common v0.54.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.25.0 // indirect
golang.org/x/net v0.14.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20230803162519-f966b187b2e5 // indirect
google.golang.org/grpc v1.57.0
google.golang.org/protobuf v1.31.0
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.26.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20240617180043-68d350f18fd4 // indirect
google.golang.org/grpc v1.64.0
google.golang.org/protobuf v1.34.2
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
)
Loading
Loading