callopt

package
v0.9.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2024 License: Apache-2.0 Imports: 12 Imported by: 1,041

Documentation

Overview

Package callopt contains options that control the behavior of client on request level.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CallOptions added in v0.4.0

type CallOptions struct {

	// export field for using in client
	RetryPolicy    retry.Policy
	Fallback       *fallback.Policy
	CompressorName string
	// contains filtered or unexported fields
}

func Apply

func Apply(cos []Option, cfg rpcinfo.MutableRPCConfig, svr remoteinfo.RemoteInfo, locks *client.ConfigLocks, httpResolver http.Resolver) (string, *CallOptions)

Apply applies call options to the rpcinfo.RPCConfig and internal.RemoteInfo of kitex client. The return value records the name and arguments of each option. This function is for internal purpose only.

func (*CallOptions) Recycle added in v0.4.0

func (co *CallOptions) Recycle()

Recycle zeros the call option and put it to the pool.

type Option

type Option struct {
	// contains filtered or unexported fields
}

Option is a series of options used at the beginning of a RPC call.

func NewOption added in v0.9.0

func NewOption(f func(o *CallOptions, di *strings.Builder)) Option

NewOption returns a new Option with the given function. It's useful for converting streamcall.Option back to a callopt.Option

func WithConnectTimeout

func WithConnectTimeout(d time.Duration) Option

WithConnectTimeout specifies the connection timeout for a RPC call.

func WithFallback added in v0.5.0

func WithFallback(fb *fallback.Policy) Option

WithFallback is used to set the fallback policy for a RPC call. Demos are provided below:

demo1. call with fallback for error
	`resp, err := cli.Mock(ctx, req, callopt.WithFallback(fallback.ErrorFallback(yourFBFunc))`
demo2. call with fallback for error and enable reportAsFallback, which sets reportAsFallback to be true and will do report(metric) as Fallback result
	`resp, err := cli.Mock(ctx, req, callopt.WithFallback(fallback.ErrorFallback(yourFBFunc).EnableReportAsFallback())`

func WithGRPCCompressor added in v0.7.0

func WithGRPCCompressor(compressorName string) Option

WithGRPCCompressor specifies the compressor for the GRPC frame payload. Supported compressor names: identity, gzip Custom compressors can be registered via `encoding.RegisterCompressor`

func WithHTTPHost

func WithHTTPHost(host string) Option

WithHTTPHost specifies host in http header(work when RPC over http).

func WithHostPort

func WithHostPort(hostport string) Option

WithHostPort specifies the target address for a RPC call. The given address will overwrite the result from Resolver.

func WithRPCTimeout

func WithRPCTimeout(d time.Duration) Option

WithRPCTimeout specifies the RPC timeout for a RPC call. FIXME: callopt.WithRPCTimeout works only when client.WithRPCTimeout or client.WithTimeoutProvider is specified.

func WithRetryPolicy added in v0.4.0

func WithRetryPolicy(p retry.Policy) Option

WithRetryPolicy sets the retry policy for a RPC call. Build retry.Policy with retry.BuildFailurePolicy or retry.BuildBackupRequest instead of building retry.Policy directly. Demos are provided below:

  demo1. call with failure retry policy, default retry error is Timeout
  	`resp, err := cli.Mock(ctx, req, callopt.WithRetryPolicy(retry.BuildFailurePolicy(retry.NewFailurePolicy())))`
  demo2. call with backup request policy
  	`bp := retry.NewBackupPolicy(10)
	 	bp.WithMaxRetryTimes(1)
  	resp, err := cli.Mock(ctx, req, callopt.WithRetryPolicy(retry.BuildBackupRequest(bp)))`

func WithTag

func WithTag(key, val string) Option

WithTag sets the tags for service discovery for a RPC call.

func WithURL

func WithURL(url string) Option

WithURL specifies the target for a RPC call with url. The given url will be resolved to hostport and overwrites the result from Resolver.

func (Option) F added in v0.9.0

func (o Option) F() func(o *CallOptions, di *strings.Builder)

F returns the function of the option. It's useful for creating streamcall.Option from existing callopt.Option Note: not all callopt.Option(s) are available for stream clients.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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