瀏覽代碼

chore: remove simple methods, inlined (#2768)

Kevin Wan 2 年之前
父節點
當前提交
0c786ca849

+ 0 - 13
zrpc/internal/chainclientinterceptors.go

@@ -1,13 +0,0 @@
-package internal
-
-import "google.golang.org/grpc"
-
-// WithStreamClientInterceptors uses given client stream interceptors.
-func WithStreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) grpc.DialOption {
-	return grpc.WithChainStreamInterceptor(interceptors...)
-}
-
-// WithUnaryClientInterceptors uses given client unary interceptors.
-func WithUnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) grpc.DialOption {
-	return grpc.WithChainUnaryInterceptor(interceptors...)
-}

+ 0 - 17
zrpc/internal/chainclientinterceptors_test.go

@@ -1,17 +0,0 @@
-package internal
-
-import (
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func TestWithStreamClientInterceptors(t *testing.T) {
-	opts := WithStreamClientInterceptors()
-	assert.NotNil(t, opts)
-}
-
-func TestWithUnaryClientInterceptors(t *testing.T) {
-	opts := WithUnaryClientInterceptors()
-	assert.NotNil(t, opts)
-}

+ 0 - 13
zrpc/internal/chainserverinterceptors.go

@@ -1,13 +0,0 @@
-package internal
-
-import "google.golang.org/grpc"
-
-// WithStreamServerInterceptors uses given server stream interceptors.
-func WithStreamServerInterceptors(interceptors ...grpc.StreamServerInterceptor) grpc.ServerOption {
-	return grpc.ChainStreamInterceptor(interceptors...)
-}
-
-// WithUnaryServerInterceptors uses given server unary interceptors.
-func WithUnaryServerInterceptors(interceptors ...grpc.UnaryServerInterceptor) grpc.ServerOption {
-	return grpc.ChainUnaryInterceptor(interceptors...)
-}

+ 0 - 17
zrpc/internal/chainserverinterceptors_test.go

@@ -1,17 +0,0 @@
-package internal
-
-import (
-	"testing"
-
-	"github.com/stretchr/testify/assert"
-)
-
-func TestWithStreamServerInterceptors(t *testing.T) {
-	opts := WithStreamServerInterceptors()
-	assert.NotNil(t, opts)
-}
-
-func TestWithUnaryServerInterceptors(t *testing.T) {
-	opts := WithUnaryServerInterceptors()
-	assert.NotNil(t, opts)
-}

+ 8 - 5
zrpc/internal/client.go

@@ -76,7 +76,8 @@ func (c *client) buildDialOptions(opts ...ClientOption) []grpc.DialOption {
 
 	var options []grpc.DialOption
 	if !cliOpts.Secure {
-		options = append([]grpc.DialOption(nil), grpc.WithTransportCredentials(insecure.NewCredentials()))
+		options = append([]grpc.DialOption(nil),
+			grpc.WithTransportCredentials(insecure.NewCredentials()))
 	}
 
 	if !cliOpts.NonBlock {
@@ -84,8 +85,8 @@ func (c *client) buildDialOptions(opts ...ClientOption) []grpc.DialOption {
 	}
 
 	options = append(options,
-		WithUnaryClientInterceptors(c.buildUnaryInterceptors(cliOpts.Timeout)...),
-		WithStreamClientInterceptors(c.buildStreamInterceptors()...),
+		grpc.WithChainUnaryInterceptor(c.buildUnaryInterceptors(cliOpts.Timeout)...),
+		grpc.WithChainStreamInterceptor(c.buildStreamInterceptors()...),
 	)
 
 	return append(options, cliOpts.DialOptions...)
@@ -162,7 +163,8 @@ func WithNonBlock() ClientOption {
 // WithStreamClientInterceptor returns a func to customize a ClientOptions with given interceptor.
 func WithStreamClientInterceptor(interceptor grpc.StreamClientInterceptor) ClientOption {
 	return func(options *ClientOptions) {
-		options.DialOptions = append(options.DialOptions, WithStreamClientInterceptors(interceptor))
+		options.DialOptions = append(options.DialOptions,
+			grpc.WithChainStreamInterceptor(interceptor))
 	}
 }
 
@@ -184,6 +186,7 @@ func WithTransportCredentials(creds credentials.TransportCredentials) ClientOpti
 // WithUnaryClientInterceptor returns a func to customize a ClientOptions with given interceptor.
 func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) ClientOption {
 	return func(options *ClientOptions) {
-		options.DialOptions = append(options.DialOptions, WithUnaryClientInterceptors(interceptor))
+		options.DialOptions = append(options.DialOptions,
+			grpc.WithChainUnaryInterceptor(interceptor))
 	}
 }

+ 2 - 2
zrpc/internal/rpcserver.go

@@ -63,8 +63,8 @@ func (s *rpcServer) Start(register RegisterFn) error {
 	unaryInterceptors = append(unaryInterceptors, s.unaryInterceptors...)
 	streamInterceptors := s.buildStreamInterceptors()
 	streamInterceptors = append(streamInterceptors, s.streamInterceptors...)
-	options := append(s.options, WithUnaryServerInterceptors(unaryInterceptors...),
-		WithStreamServerInterceptors(streamInterceptors...))
+	options := append(s.options, grpc.ChainUnaryInterceptor(unaryInterceptors...),
+		grpc.ChainStreamInterceptor(streamInterceptors...))
 	server := grpc.NewServer(options...)
 	register(server)