protoclient

package
v1.25.1-0...-2fdc35d Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2021 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenClientStream

func OpenClientStream(ctx context.Context, cli Client, prm OpenClientStreamPrm, res *OpenClientStreamRes) error

OpenClientStream initializes communication session by RPC info, opens client-side stream and wraps it into .

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

Context, client and res must not be nil.

func OpenServerStream

func OpenServerStream(ctx context.Context, cli Client, prm OpenServerStreamPrm, res *OpenServerStreamRes) 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. CloseSend must be called once.

Context, client and res must not be nil.

func SendUnary

func SendUnary(ctx context.Context, cli Client, prm SendUnaryPrm, _ *SendUnaryRes) error

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

Client connection should be established.

Context and client must not be nil. SendUnaryRes is currently ignored and can be nil. It is left for potential occasion of results.

func SetURIAddress

func SetURIAddress(prm *DialPrm, address string) bool

SetURIAddress tries to parse URI from string and pass host to prm.SetAddress. Also updates TLS config. Returns true if prm is modified.

If address is not a valid URI, returns false.

Format of the URI:

[scheme://]host:port

Supported schemes:

  • grpc;
  • grpcs.

If scheme is not supported, returns false. If URI has grpcs scheme, empty TLS config is used.

Should not be used with SetAddress and SetTLSConfig if result is true.

Types

type Client

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

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

Should be created using DialPrm.Dial.

Client is one-time use, and should only be used within an open connection.

func (Client) Close

func (x Client) Close() error

Close closes opened connection.

Must be called only after successful initialization.

func (Client) RPC

func (x Client) RPC(ctx context.Context, prm RPCPrm, res *RPCRes) error

Communicate initiates a messaging session within the parameterized RPC. Connection must be opened before (Dial).

Context is used for message exchange. Timeout can be configured using context.WithTimeout.

If there is no error, res.Messager() can be used for communication. It should be closed finally.

Panics if ctx or res is nil, CallMethodInfo has empty service or method name.

type DialPrm

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

DialPrm groups the Dial parameters.

func (DialPrm) Dial

func (x DialPrm) Dial(res *DialRes) error

Dial opens client connection and initializes Client with it.

Blocks until successful connection or timeout. If TLS is configured, connection is opened using it.

DialRes must not be nil. Client can be received using res.Client().

func (*DialPrm) SetAddress

func (x *DialPrm) SetAddress(addr string)

SetAddress sets network address as a connection target.

func (*DialPrm) SetTLSConfig

func (x *DialPrm) SetTLSConfig(c *tls.Config)

SetTLSConfig sets TLS client configuration.

func (*DialPrm) SetTimeout

func (x *DialPrm) SetTimeout(timeout time.Duration)

SetTimeout sets timeout for dialing.

type DialRes

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

DialPrm groups the Dial results.

func (DialRes) Client

func (x DialRes) Client() Client

Client returns initialized Client instance.

Should be called only after successful Dial.

type MessageReadWriter

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

MessageReadWriter is a component for transmitting raw Protobuf messages.

func (MessageReadWriter) CloseSend

func (x MessageReadWriter) CloseSend() error

CloseSend ends writing messages to the server.

All WriteMessage calls must be done before closing.

func (MessageReadWriter) ReadMessage

func (x MessageReadWriter) ReadMessage(m message.Message) error

ReadMessage reads the next message from the remote server, and writes it to the message.Message.

Returns io.EOF if there are no more messages to read. ReadMessage should not be called after io.EOF occasion.

func (MessageReadWriter) WriteMessage

func (x MessageReadWriter) WriteMessage(m message.Message) error

WriteMessage writes the next message.Message.

WriteMessage should not be called after any error or after CloseSend.

type MessageReaderCloser

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

MessageReaderCloser is a wrapper over MessageReadWriter which shadows WriteMessage and CloseSend methods method in redefined ReadMessage.

func (*MessageReaderCloser) ReadMessage

func (s *MessageReaderCloser) ReadMessage(msg message.Message) error

ReadMessage calls WriteMessage on underlying MessageReadWriter on first call, and then performs ReadMessage. Calls CloseSend if ReadMessage returned io.EOF.

type MessageWriterCloser

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

MessageWriterCloser is a wrapper over MessageReadWriter which shadows ReadMessage and CloseSend methods to combine them in single CloseSend method.

func (MessageWriterCloser) CloseSend

func (x MessageWriterCloser) CloseSend() error

CloseSend calls CloseSend and reads the response message on underlying MessageReadWriter.

func (MessageWriterCloser) WriteMessage

func (x MessageWriterCloser) WriteMessage(m message.Message) error

WriteMessage calls WriteMessage on underlying MessageReadWriter.

type OpenClientStreamPrm

type OpenClientStreamPrm struct {
	RPCPrm
	// contains filtered or unexported fields
}

OpenClientStreamPrm inherits RPCPrm with additional parameters for OpenClientStream.

func (*OpenClientStreamPrm) SetResponse

func (x *OpenClientStreamPrm) SetResponse(resp message.Message)

SetResponse sets response message for the client-streaming RPC communication.

type OpenClientStreamRes

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

OpenClientStreamRes groups the results of OpenClientStream.

func (OpenClientStreamRes) Messager

Messager initialized MessageReaderCloser which can be used for request writing.

Should be closed after communication is completed. Parameterized response is after the successful Close.

type OpenServerStreamPrm

type OpenServerStreamPrm struct {
	RPCPrm
	// contains filtered or unexported fields
}

OpenServerStreamPrm inherits RPCPrm with additional parameters for OpenServerStream.

func (*OpenServerStreamPrm) SetRequest

func (x *OpenServerStreamPrm) SetRequest(resp message.Message)

SetResponse sets request message for the server-streaming RPC communication.

type OpenServerStreamRes

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

OpenServerStreamRes groups the results of OpenServerStream.

func (OpenServerStreamRes) Messager

Messager initialized MessageReaderCloser which can be used for response reading.

Should be closed after communication is completed. Parameterized response is after the successful Close.

type RPCPrm

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

RPCPrm groups the parameters of Client.RPC call.

func (*RPCPrm) SetCallMethodInfo

func (x *RPCPrm) SetCallMethodInfo(mInfo common.CallMethodInfo)

SetCallMethodInfo sets information about the RPC service and method.

Required parameter, service and names must not be empty.

type RPCRes

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

RPCRes groups the results of Client.RPC call.

func (RPCRes) Messager

func (x RPCRes) Messager() MessageReadWriter

Messager returns initialized MessageReadWriter which can be used for message exchange.

Should be called only after successful Client.RPC call. MessageReadWriter should be closed after communication is completed.

type SendUnaryPrm

type SendUnaryPrm struct {
	RPCPrm
	// contains filtered or unexported fields
}

SendUnaryPrm inherits RPCPrm with additional parameters for SendUnary.

func (*SendUnaryPrm) SetMessages

func (x *SendUnaryPrm) SetMessages(req, resp message.Message)

SetMessages sets request and response messages for the unary RPC communication.

Must not be nil.

type SendUnaryRes

type SendUnaryRes struct{}

OpenClientStreamRes groups the results of OpenClientStream.

Jump to

Keyboard shortcuts

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