chore: remove simple methods, inlined (#2768)
This commit is contained in:
@@ -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...)
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -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...)
|
|
||||||
}
|
|
||||||
@@ -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)
|
|
||||||
}
|
|
||||||
@@ -76,7 +76,8 @@ func (c *client) buildDialOptions(opts ...ClientOption) []grpc.DialOption {
|
|||||||
|
|
||||||
var options []grpc.DialOption
|
var options []grpc.DialOption
|
||||||
if !cliOpts.Secure {
|
if !cliOpts.Secure {
|
||||||
options = append([]grpc.DialOption(nil), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
options = append([]grpc.DialOption(nil),
|
||||||
|
grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cliOpts.NonBlock {
|
if !cliOpts.NonBlock {
|
||||||
@@ -84,8 +85,8 @@ func (c *client) buildDialOptions(opts ...ClientOption) []grpc.DialOption {
|
|||||||
}
|
}
|
||||||
|
|
||||||
options = append(options,
|
options = append(options,
|
||||||
WithUnaryClientInterceptors(c.buildUnaryInterceptors(cliOpts.Timeout)...),
|
grpc.WithChainUnaryInterceptor(c.buildUnaryInterceptors(cliOpts.Timeout)...),
|
||||||
WithStreamClientInterceptors(c.buildStreamInterceptors()...),
|
grpc.WithChainStreamInterceptor(c.buildStreamInterceptors()...),
|
||||||
)
|
)
|
||||||
|
|
||||||
return append(options, cliOpts.DialOptions...)
|
return append(options, cliOpts.DialOptions...)
|
||||||
@@ -162,7 +163,8 @@ func WithNonBlock() ClientOption {
|
|||||||
// WithStreamClientInterceptor returns a func to customize a ClientOptions with given interceptor.
|
// WithStreamClientInterceptor returns a func to customize a ClientOptions with given interceptor.
|
||||||
func WithStreamClientInterceptor(interceptor grpc.StreamClientInterceptor) ClientOption {
|
func WithStreamClientInterceptor(interceptor grpc.StreamClientInterceptor) ClientOption {
|
||||||
return func(options *ClientOptions) {
|
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.
|
// WithUnaryClientInterceptor returns a func to customize a ClientOptions with given interceptor.
|
||||||
func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) ClientOption {
|
func WithUnaryClientInterceptor(interceptor grpc.UnaryClientInterceptor) ClientOption {
|
||||||
return func(options *ClientOptions) {
|
return func(options *ClientOptions) {
|
||||||
options.DialOptions = append(options.DialOptions, WithUnaryClientInterceptors(interceptor))
|
options.DialOptions = append(options.DialOptions,
|
||||||
|
grpc.WithChainUnaryInterceptor(interceptor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ func (s *rpcServer) Start(register RegisterFn) error {
|
|||||||
unaryInterceptors = append(unaryInterceptors, s.unaryInterceptors...)
|
unaryInterceptors = append(unaryInterceptors, s.unaryInterceptors...)
|
||||||
streamInterceptors := s.buildStreamInterceptors()
|
streamInterceptors := s.buildStreamInterceptors()
|
||||||
streamInterceptors = append(streamInterceptors, s.streamInterceptors...)
|
streamInterceptors = append(streamInterceptors, s.streamInterceptors...)
|
||||||
options := append(s.options, WithUnaryServerInterceptors(unaryInterceptors...),
|
options := append(s.options, grpc.ChainUnaryInterceptor(unaryInterceptors...),
|
||||||
WithStreamServerInterceptors(streamInterceptors...))
|
grpc.ChainStreamInterceptor(streamInterceptors...))
|
||||||
server := grpc.NewServer(options...)
|
server := grpc.NewServer(options...)
|
||||||
register(server)
|
register(server)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user