Documentation
¶
Overview ¶
Package grpcdynamic provides a dynamic RPC stub. It can be used to invoke RPC methods that are unknown at compile time, using method descriptors to drive the invocations at runtime. The actual request and response messages may be (and likely often are) dynamic messages.
Index ¶
- type BidiStream
- type ClientStream
- type ServerStream
- type Stub
- func (s *Stub) InvokeRPC(ctx context.Context, method protoreflect.MethodDescriptor, ...) (proto.Message, error)
- func (s *Stub) InvokeRPCBidiStream(ctx context.Context, method protoreflect.MethodDescriptor, ...) (*BidiStream, error)
- func (s *Stub) InvokeRPCClientStream(ctx context.Context, method protoreflect.MethodDescriptor, ...) (*ClientStream, error)
- func (s *Stub) InvokeRPCServerStream(ctx context.Context, method protoreflect.MethodDescriptor, ...) (*ServerStream, error)
- type StubOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BidiStream ¶
type BidiStream struct {
// contains filtered or unexported fields
}
BidiStream represents a bi-directional stream for sending messages to and receiving messages from a server. The header and trailer metadata sent by the server can also be queried.
func (*BidiStream) CloseSend ¶
func (s *BidiStream) CloseSend() error
CloseSend indicates the request stream has ended. Invoke this after all request messages are sent (even if there are zero such messages).
func (BidiStream) Header ¶
Header returns any header metadata sent by the server (blocks if necessary until headers are received).
func (*BidiStream) RecvMsg ¶
func (s *BidiStream) RecvMsg() (proto.Message, error)
RecvMsg returns the next message in the response stream or an error. If the stream has completed normally, the error is io.EOF. Otherwise, the error indicates the nature of the abnormal termination of the stream.
func (*BidiStream) SendMsg ¶
func (s *BidiStream) SendMsg(m proto.Message) error
SendMsg sends a request message to the server. If it returns io.EOF, the server has already ended the call; use RecvMsg to get the call's status.
type ClientStream ¶
type ClientStream struct {
// contains filtered or unexported fields
}
ClientStream represents the client side of a client-streaming call. Messages can be sent and, when done, the unary server message and header and trailer metadata can be queried.
func (*ClientStream) CloseAndReceive ¶
func (s *ClientStream) CloseAndReceive() (proto.Message, error)
CloseAndReceive closes the outgoing request stream and then blocks for the server's response.
func (ClientStream) Header ¶
Header returns any header metadata sent by the server (blocks if necessary until headers are received).
func (*ClientStream) SendMsg ¶
func (s *ClientStream) SendMsg(m proto.Message) error
SendMsg sends a request message to the server. If it returns io.EOF, the server has already ended the call; use CloseAndReceive to get the call's status.
type ServerStream ¶
type ServerStream struct {
// contains filtered or unexported fields
}
ServerStream represents a response stream from a server. Messages in the stream can be queried as can header and trailer metadata sent by the server.
func (ServerStream) Header ¶
Header returns any header metadata sent by the server (blocks if necessary until headers are received).
func (*ServerStream) RecvMsg ¶
func (s *ServerStream) RecvMsg() (proto.Message, error)
RecvMsg returns the next message in the response stream or an error. If the stream has completed normally, the error is io.EOF. Otherwise, the error indicates the nature of the abnormal termination of the stream.
type Stub ¶
type Stub struct {
// contains filtered or unexported fields
}
Stub is an RPC client stub, used for dynamically dispatching RPCs to a server.
func NewStub ¶
func NewStub(channel grpc.ClientConnInterface, opts ...StubOption) *Stub
NewStub creates a new RPC stub that uses the given channel for dispatching RPCs.
func (*Stub) InvokeRPC ¶
func (s *Stub) InvokeRPC(ctx context.Context, method protoreflect.MethodDescriptor, request proto.Message, opts ...grpc.CallOption) (proto.Message, error)
InvokeRPC sends a unary RPC and returns the response. Use this for unary methods.
func (*Stub) InvokeRPCBidiStream ¶
func (s *Stub) InvokeRPCBidiStream(ctx context.Context, method protoreflect.MethodDescriptor, opts ...grpc.CallOption) (*BidiStream, error)
InvokeRPCBidiStream creates a new stream that is used to both send request messages and receive response messages. Use this for bidi-streaming methods.
To release the stream's resources, callers must either call RecvMsg until it returns an error (which is io.EOF when the stream completes normally) or cancel ctx. Usually, the server doesn't end the stream until after the client calls CloseSend.
func (*Stub) InvokeRPCClientStream ¶
func (s *Stub) InvokeRPCClientStream(ctx context.Context, method protoreflect.MethodDescriptor, opts ...grpc.CallOption) (*ClientStream, error)
InvokeRPCClientStream creates a new stream that is used to send request messages and, at the end, receive the response message. Use this for client-streaming methods.
To release the stream's resources, callers must either call CloseAndReceive or cancel ctx.
func (*Stub) InvokeRPCServerStream ¶
func (s *Stub) InvokeRPCServerStream(ctx context.Context, method protoreflect.MethodDescriptor, request proto.Message, opts ...grpc.CallOption) (*ServerStream, error)
InvokeRPCServerStream sends a single request message and returns the response stream. Use this for server-streaming methods.
To release the stream's resources, callers must either call RecvMsg until it returns an error (which is io.EOF when the stream completes normally) or cancel ctx.
type StubOption ¶
type StubOption interface {
// contains filtered or unexported methods
}
StubOption is an option that can be used to customize behavior when creating a Stub.
func WithResolver ¶
func WithResolver(res protoresolve.SerializationResolver) StubOption
WithResolver returns a StubOption that causes a Stub to use the given resolver for de-serializing response messages. If not specified, protoregistry.GlobalTypes is used. If the given resolver does not support the response message type, a dynamic message is used. The given resolver is also used for recognizing extensions in response messages.