grpclient

package
v1.58.1 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2023 License: Apache-2.0 Imports: 16 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConnCanceled

func IsConnCanceled(err error) bool

IsConnCanceled returns true, if error is from a closed gRPC connection. ref. https://github.com/grpc/grpc-go/pull/1854

Types

type Client

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

Client provides and manages an etcd v3 client session.

func NewClient

func NewClient(cfg *Config) (*Client, error)

func (*Client) ActiveConnection

func (c *Client) ActiveConnection() *grpc.ClientConn

ActiveConnection returns the current in-use connection

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client's etcd connections.

func (*Client) Ctx

func (c *Client) Ctx() context.Context

Ctx is a context for "out of band" messages (e.g., for sending "clean up" message when another context is canceled). It is canceled on client Close().

func (*Client) Dial

func (c *Client) Dial(ep string) (*grpc.ClientConn, error)

Dial connects to a single endpoint using the client's config.

func (*Client) Endpoints

func (c *Client) Endpoints() []string

Endpoints lists the registered endpoints for the client.

func (*Client) GetCallOpts

func (c *Client) GetCallOpts() []grpc.CallOption

func (*Client) SetEndpoints

func (c *Client) SetEndpoints(eps []string)

SetEndpoints updates client's endpoints.

type Config

type Config struct {
	// Endpoints is a list of URLs.
	Endpoints []string

	// Endpoints address attributes
	// see: https://github.com/grpc/grpc-go/blob/v1.36.0/attributes/attributes.go#L30
	Attributes map[string]*attributes.Attributes

	// load balance name, current support balancer.RoundRobinBalanceName, balancer.WeightedRobinBalanceName
	BalanceName string

	// AutoSyncInterval is the interval to update endpoints with its latest members.
	// 0 disables auto-sync. By default auto-sync is disabled.
	AutoSyncInterval time.Duration

	// DialTimeout is the timeout for failing to establish a connection.
	DialTimeout time.Duration

	// DialKeepAliveTime is the time after which client pings the server to see if
	// transport is alive.
	DialKeepAliveTime time.Duration

	// DialKeepAliveTimeout is the time that the client waits for a response for the
	// keep-alive probe. If the response is not received in this time, the connection is closed.
	DialKeepAliveTimeout time.Duration

	// MaxCallSendMsgSize is the client-side request send limit in bytes.
	// If 0, it defaults to 2.0 MiB (2 * 1024 * 1024).
	// Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit.
	// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
	MaxCallSendMsgSize int

	// MaxCallRecvMsgSize is the client-side response receive limit.
	// If 0, it defaults to "math.MaxInt32", because range response can
	// easily exceed request send limits.
	// Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit.
	// ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
	MaxCallRecvMsgSize int

	// DialOptions is a list of dial options for the grpc client (e.g., for interceptors).
	// For example, pass "grpc.WithBlock()" to block until the underlying connection is up.
	// Without this, Dial returns immediately and connecting the server happens in background.
	DialOptions []grpc.DialOption

	// Context is the default client context; it can be used to cancel grpc dial out and
	// other operations that do not have an explicit context.
	Context context.Context

	PermitWithoutStream bool
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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