fix golint issues in zrpc (#531)

This commit is contained in:
Kevin Wan
2021-03-01 23:52:44 +08:00
committed by GitHub
parent dd393351cc
commit 51de0d0620
29 changed files with 108 additions and 13 deletions

View File

@@ -23,11 +23,18 @@ func init() {
}
type (
// Client interface wraps the Conn method.
Client interface {
Conn() *grpc.ClientConn
}
// A ClientOptions is a client options.
ClientOptions struct {
Timeout time.Duration
DialOptions []grpc.DialOption
}
// ClientOption defines the method to customize a ClientOptions.
ClientOption func(options *ClientOptions)
client struct {
@@ -35,7 +42,8 @@ type (
}
)
func NewClient(target string, opts ...ClientOption) (*client, error) {
// NewClient returns a Client.
func NewClient(target string, opts ...ClientOption) (Client, error) {
var cli client
opts = append([]ClientOption{WithDialOption(grpc.WithBalancerName(p2c.Name))}, opts...)
if err := cli.dial(target, opts...); err != nil {
@@ -92,18 +100,21 @@ func (c *client) dial(server string, opts ...ClientOption) error {
return nil
}
// WithDialOption returns a func to customize a ClientOptions with given dial option.
func WithDialOption(opt grpc.DialOption) ClientOption {
return func(options *ClientOptions) {
options.DialOptions = append(options.DialOptions, opt)
}
}
// WithTimeout returns a func to customize a ClientOptions with given timeout.
func WithTimeout(timeout time.Duration) ClientOption {
return func(options *ClientOptions) {
options.Timeout = timeout
}
}
// 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))