Version specifies the gax-go version being used.
const Version = internal.Version
var ( // GoVersion is a header-safe representation of the current runtime // environment's Go version. This is for GAX consumers that need to // report the Go runtime version in API calls. GoVersion string )
func BuildHeaders(ctx context.Context, keyvals ...string) http.Header
BuildHeaders is for use by the Google Cloud Libraries only. See package github.com/googleapis/gax-go/v2/callctx for help setting/retrieving request/response headers.
BuildHeaders returns a new http.Header that merges the provided keyvals header pairs with any existing metadata/headers in the provided context. keyvals should have a corresponding value for every key provided. If there is an odd number of keyvals this method will panic. Existing values for keys will not be overwritten, instead provided values will be appended to the list of existing values.
func DetermineContentType(media io.Reader) (io.Reader, string)
DetermineContentType determines the content type of the supplied reader. The content of media will be sniffed to determine the content type. After calling DetectContentType the caller must not perform further reads on media, but rather read from the Reader that is returned.
func InsertMetadataIntoOutgoingContext(ctx context.Context, keyvals ...string) context.Context
InsertMetadataIntoOutgoingContext is for use by the Google Cloud Libraries only. See package github.com/googleapis/gax-go/v2/callctx for help setting/retrieving request/response headers.
InsertMetadataIntoOutgoingContext returns a new context that merges the provided keyvals metadata pairs with any existing metadata/headers in the provided context. keyvals should have a corresponding value for every key provided. If there is an odd number of keyvals this method will panic. Existing values for keys will not be overwritten, instead provided values will be appended to the list of existing values.
func Invoke(ctx context.Context, call APICall, opts ...CallOption) error
Invoke calls the given APICall, performing retries as specified by opts, if any.
▹ Example (Grpc)
▹ Example (Http)
func Sleep(ctx context.Context, d time.Duration) error
Sleep is similar to time.Sleep, but it can be interrupted by ctx.Done() closing. If interrupted, Sleep returns ctx.Err().
func XGoogHeader(keyval ...string) string
XGoogHeader is for use by the Google Cloud Libraries only. See package github.com/googleapis/gax-go/v2/callctx for help setting/retrieving request/response headers.
XGoogHeader formats key-value pairs. The resulting string is suitable for x-goog-api-client header.
APICall is a user defined call stub.
type APICall func(context.Context, CallSettings) error
Backoff implements exponential backoff. The wait time between retries is a random value between 0 and the "retry period" - the time between retries. The retry period starts at Initial and increases by the factor of Multiplier every retry, but is capped at Max.
Note: MaxNumRetries / RPCDeadline is specifically not provided. These should be built on top of Backoff.
type Backoff struct { // Initial is the initial value of the retry period, defaults to 1 second. Initial time.Duration // Max is the maximum value of the retry period, defaults to 30 seconds. Max time.Duration // Multiplier is the factor by which the retry period increases. // It should be greater than 1 and defaults to 2. Multiplier float64 // contains filtered or unexported fields }
▹ Example
func (bo *Backoff) Pause() time.Duration
Pause returns the next time.Duration that the caller should use to backoff.
CallOption is an option used by Invoke to control behaviors of RPC calls. CallOption works by modifying relevant fields of CallSettings.
type CallOption interface { // Resolve applies the option by modifying cs. Resolve(cs *CallSettings) }
func WithGRPCOptions(opt ...grpc.CallOption) CallOption
WithGRPCOptions allows passing gRPC call options during client creation.
func WithPath(p string) CallOption
WithPath applies a Path override to the HTTP-based APICall.
This is for internal use only.
func WithRetry(fn func() Retryer) CallOption
WithRetry sets CallSettings.Retry to fn.
func WithTimeout(t time.Duration) CallOption
WithTimeout is a convenience option for setting a context.WithTimeout on the singular context.Context used for **all** APICall attempts. Calculated from the start of the first APICall attempt. If the context.Context provided to Invoke already has a Deadline set, that will always be respected over the deadline calculated using this option.
CallSettings allow fine-grained control over how calls are made.
type CallSettings struct { // Retry returns a Retryer to be used to control retry logic of a method call. // If Retry is nil or the returned Retryer is nil, the call will not be retried. Retry func() Retryer // CallOptions to be forwarded to GRPC. GRPC []grpc.CallOption // Path is an HTTP override for an APICall. Path string // contains filtered or unexported fields }
ProtoJSONStream represents a wrapper for consuming a stream of protobuf messages encoded using protobuf-JSON format. More information on this format can be found at https://developers.google.com/protocol-buffers/docs/proto3#json. The stream must appear as a comma-delimited, JSON array of obbjects with opening and closing square braces.
This is for internal use only.
type ProtoJSONStream struct {
// contains filtered or unexported fields
}
▹ Example
func NewProtoJSONStreamReader(rc io.ReadCloser, typ protoreflect.MessageType) *ProtoJSONStream
NewProtoJSONStreamReader accepts a stream of bytes via an io.ReadCloser that are protobuf-JSON encoded protobuf messages of the given type. The ProtoJSONStream must be closed when done.
This is for internal use only.
func (s *ProtoJSONStream) Close() error
Close closes the stream so that resources are cleaned up.
func (s *ProtoJSONStream) Recv() (proto.Message, error)
Recv decodes the next protobuf message in the stream or returns io.EOF if the stream is done. It is not safe to call Recv on the same stream from different goroutines, just like it is not safe to do so with a single gRPC stream. Type-cast the protobuf message returned to the type provided at ProtoJSONStream creation. Calls to Recv after calling Close will produce io.EOF.
Retryer is used by Invoke to determine retry behavior.
type Retryer interface { // Retry reports whether a request should be retried and how long to pause before retrying // if the previous attempt returned with err. Invoke never calls Retry with nil error. Retry(err error) (pause time.Duration, shouldRetry bool) }
func OnCodes(cc []codes.Code, bo Backoff) Retryer
OnCodes returns a Retryer that retries if and only if the previous attempt returns a GRPC error whose error code is stored in cc. Pause times between retries are specified by bo.
bo is only used for its parameters; each Retryer has its own copy.
▹ Example
func OnErrorFunc(bo Backoff, shouldRetry func(err error) bool) Retryer
OnErrorFunc returns a Retryer that retries if and only if the previous attempt returns an error that satisfies shouldRetry.
Pause times between retries are specified by bo. bo is only used for its parameters; each Retryer has its own copy.
▹ Example
func OnHTTPCodes(bo Backoff, cc ...int) Retryer
OnHTTPCodes returns a Retryer that retries if and only if the previous attempt returns a googleapi.Error whose status code is stored in cc. Pause times between retries are specified by bo.
bo is only used for its parameters; each Retryer has its own copy.
▹ Example