DialOption returns the config as a grpc.DialOptions.
()
| 665 | |
| 666 | // DialOption returns the config as a grpc.DialOptions. |
| 667 | func (cfg *grpcConfig) DialOption() ([]grpc.DialOption, error) { |
| 668 | var opts []grpc.DialOption |
| 669 | tlsOpts, err := cfg.TLS.GetGRPCDialOptions(cfg.TLSEnabled) |
| 670 | if err != nil { |
| 671 | return nil, err |
| 672 | } |
| 673 | opts = append(opts, tlsOpts...) |
| 674 | |
| 675 | var unaryClientInterceptors []grpc.UnaryClientInterceptor |
| 676 | if cfg.BackoffOnRatelimits { |
| 677 | unaryClientInterceptors = append([]grpc.UnaryClientInterceptor{newBackoffRetry(cfg.BackoffConfig)}, unaryClientInterceptors...) |
| 678 | } |
| 679 | |
| 680 | if cfg.RateLimit > 0 { |
| 681 | unaryClientInterceptors = append([]grpc.UnaryClientInterceptor{newRateLimiter(cfg)}, unaryClientInterceptors...) |
| 682 | } |
| 683 | |
| 684 | return append( |
| 685 | opts, |
| 686 | grpc.WithDefaultCallOptions(cfg.CallOptions()...), |
| 687 | grpc.WithChainUnaryInterceptor(unaryClientInterceptors...), |
| 688 | grpc.WithKeepaliveParams(keepalive.ClientParameters{ |
| 689 | Time: time.Second * 20, |
| 690 | Timeout: time.Second * 10, |
| 691 | PermitWithoutStream: true, |
| 692 | }), |
| 693 | ), nil |
| 694 | } |
| 695 | |
| 696 | func newBackoffRetry(cfg backoff.Config) grpc.UnaryClientInterceptor { |
| 697 | return func(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error { |
no test coverage detected