client

package
v0.0.0-...-0352b5b Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2024 License: Apache-2.0 Imports: 15 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseURI

func ParseURI(s string) (string, bool, error)

ParseURI parses s as address and returns a host and a flag indicating that TLS is enabled. If multi-address is provided the argument is returned unchanged.

func SendUnary

func SendUnary(cli *Client, info common.CallMethodInfo, req, resp message.Message, opts ...CallOption) error

SendUnary initializes communication session by RPC info, performs unary RPC and closes the session.

Types

type CallOption

type CallOption func(*callParameters)

CallOption is a messaging session option within Protobuf RPC.

func WithContext

func WithContext(ctx context.Context) CallOption

WithContext returns option to specify call context. If provided, all network communications will be based on this context. Otherwise, context.Background() is used.

Context SHOULD NOT be nil.

func WithDialer

func WithDialer(dialer func(context.Context, grpc.ClientConnInterface) error) CallOption

WithDialer returns option to specify grpc dialer. If passed, it will be called after the connection is successfully created.

type Client

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

Client represents client for exchanging messages with a remote server using Protobuf RPC.

func New

func New(opts ...Option) *Client

New creates, configures via options and returns new Client instance.

func (*Client) Conn

func (c *Client) Conn() io.Closer

Conn returns underlying connection.

Returns non-nil result after the first Init() call completed without a connection error.

Client should not be used after Close() call on the connection: behavior is undefined.

func (*Client) Init

func (c *Client) Init(info common.CallMethodInfo, opts ...CallOption) (MessageReadWriter, error)

Init initiates a messaging session and returns the interface for message transmitting.

type Conn

type Conn interface {
	grpc.ClientConnInterface
	io.Closer
}

Conn is an interface for grpc client connection.

type MessageReadWriter

type MessageReadWriter interface {
	MessageReader
	MessageWriter

	// Closes the communication session.
	//
	// All calls to send/receive messages must be done before closing.
	io.Closer
}

MessageReadWriter is a component interface for transmitting raw Protobuf messages.

type MessageReader

type MessageReader interface {
	// ReadMessage reads the next Message.
	//
	// Returns io.EOF if there are no more messages to read.
	// ReadMessage should not be called after io.EOF occasion.
	ReadMessage(message.Message) error
}

MessageReader is an interface of the Message reader.

func OpenServerStream

func OpenServerStream(cli *Client, info common.CallMethodInfo, req message.Message, opts ...CallOption) (MessageReader, error)

OpenServerStream initializes communication session by RPC info, opens server-side stream and returns its interface.

All stream reads must be performed before the closing. Close must be called once.

type MessageReaderCloser

type MessageReaderCloser interface {
	MessageReader
	io.Closer
}

MessageReaderCloser wraps MessageReader and io.Closer interface.

type MessageWriter

type MessageWriter interface {
	// WriteMessage writers the next Message.
	//
	// WriteMessage should not be called after any error.
	WriteMessage(message.Message) error
}

MessageWriter is an interface of the Message writer.

type MessageWriterCloser

type MessageWriterCloser interface {
	MessageWriter
	io.Closer
}

MessageWriterCloser wraps MessageWriter and io.Closer interfaces.

func OpenClientStream

func OpenClientStream(cli *Client, info common.CallMethodInfo, resp message.Message, opts ...CallOption) (MessageWriterCloser, error)

OpenClientStream initializes communication session by RPC info, opens client-side stream and returns its interface.

All stream writes must be performed before the closing. Close must be called once.

type Option

type Option func(*cfg)

Option is a Client's option.

func WithDialTimeout

func WithDialTimeout(v time.Duration) Option

WithDialTimeout returns option to specify dial timeout of the remote server connection.

Ignored if WithGRPCConn is provided.

func WithGRPCConn

func WithGRPCConn(v Conn) Option

WithGRPCConn returns option to specify gRPC virtual connection.

func WithGRPCDialOptions

func WithGRPCDialOptions(opts []grpc.DialOption) Option

WithGRPCDialOptions returns an option to specify grpc.DialOption.

func WithNetworkAddress

func WithNetworkAddress(v string) Option

WithNetworkAddress returns option to specify network address of the remote server.

Ignored if WithGRPCConn is provided.

func WithNetworkURIAddress

func WithNetworkURIAddress(addr string, tlsCfg *tls.Config) []Option

WithNetworkURIAddress combines WithNetworkAddress and WithTLSCfg options based on arguments.

Do not use along with WithNetworkAddress and WithTLSCfg.

Ignored if WithGRPCConn is provided.

func WithRWTimeout

func WithRWTimeout(v time.Duration) Option

WithRWTimeout returns option to specify timeout for reading and writing single gRPC message.

func WithTLSCfg

func WithTLSCfg(v *tls.Config) Option

WithTLSCfg returns option to specify TLS configuration.

Ignored if WithGRPCConn is provided.

Jump to

Keyboard shortcuts

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