cloudclient

package
v0.59.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

Package cloudclient provides primitives for gRPC clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DialService

func DialService(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialService dials another Cloud Run gRPC service with the default service account's RPC credentials.

func DialServiceInsecure

func DialServiceInsecure(ctx context.Context, target string, opts ...grpc.DialOption) (*grpc.ClientConn, error)

DialServiceInsecure establishes an insecure connection to another service that must be on the local host. Only works outside of GCE, and fails if attempting to dial any other host than localhost. Should never be used in production code, only for debugging and local development.

Types

type Config

type Config struct {
	// The timeout of outgoing gRPC method calls. Set to zero to disable.
	Timeout time.Duration `default:"10s"`
	// Retry config.
	Retry RetryConfig
}

Config configures a gRPC client's default timeout and retry behavior. See: https://github.com/grpc/grpc-proto/blob/master/grpc/service_config/service_config.proto

func (*Config) AsServiceConfigJSON

func (c *Config) AsServiceConfigJSON() string

AsServiceConfigJSON returns the default method call config as a valid gRPC service JSON config.

type Middleware

type Middleware struct{}

func (*Middleware) GRPCUnaryClientInterceptor

func (l *Middleware) GRPCUnaryClientInterceptor(
	ctx context.Context,
	fullMethod string,
	request interface{},
	response interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption,
) error

GRPCUnaryClientInterceptor adds standard middleware for gRPC clients.

type RetryConfig

type RetryConfig struct {
	// Enabled indicates if retries are enabled.
	Enabled bool `default:"true"`
	// InitialBackoff is the initial exponential backoff duration.
	//
	// The initial retry attempt will occur at:
	//   random(0, initial_backoff).
	//
	// In general, the nth attempt will occur at:
	//   random(0, min(initial_backoff*backoff_multiplier**(n-1), max_backoff)).
	//
	// Must be greater than zero.
	InitialBackoff time.Duration `default:"200ms"`
	// MaxBackoff is the maximum duration between retries.
	MaxBackoff time.Duration `default:"60s"`
	// MaxAttempts is the max number of backoff attempts retried.
	MaxAttempts int `default:"5"`
	// BackoffMultiplier is the exponential backoff multiplier.
	BackoffMultiplier float64 `default:"2"`
	// RetryableStatusCodes is the set of status codes which may be retried.
	// Unknown status codes are retried by default for the sake of retrying Google Cloud HTTP load balancer errors.
	RetryableStatusCodes []codes.Code `default:"Unavailable,Unknown"`
}

RetryConfig configures default retry behavior for outgoing gRPC client calls. See: https://github.com/grpc/grpc-proto/blob/master/grpc/service_config/service_config.proto

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL