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) Context ¶
func (s *BidiStream) Context() context.Context
Context returns the context associated with this streaming operation.
func (*BidiStream) Header ¶
func (s *BidiStream) Header() (metadata.MD, error)
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.
func (*BidiStream) Trailer ¶
func (s *BidiStream) Trailer() metadata.MD
Trailer returns the trailer metadata sent by the server. It must only be called after RecvMsg returns a non-nil error (which may be EOF for normal completion of stream).
type ClientStream ¶
type ClientStream struct {
// contains filtered or unexported fields
}
ClientStream represents a response stream from a client. Messages in the stream 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) Context ¶
func (s *ClientStream) Context() context.Context
Context returns the context associated with this streaming operation.
func (*ClientStream) Header ¶
func (s *ClientStream) Header() (metadata.MD, error)
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.
func (*ClientStream) Trailer ¶
func (s *ClientStream) Trailer() metadata.MD
Trailer returns the trailer metadata sent by the server. It must only be called after RecvMsg returns a non-nil error (which may be EOF for normal completion of stream).
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) Context ¶
func (s *ServerStream) Context() context.Context
Context returns the context associated with this streaming operation.
func (*ServerStream) Header ¶
func (s *ServerStream) Header() (metadata.MD, error)
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.
func (*ServerStream) Trailer ¶
func (s *ServerStream) Trailer() metadata.MD
Trailer returns the trailer metadata sent by the server. It must only be called after RecvMsg returns a non-nil error (which may be EOF for normal completion of 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.
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.
func (*Stub) InvokeRpcServerStream ¶
func (s *Stub) InvokeRpcServerStream(ctx context.Context, method protoreflect.MethodDescriptor, request proto.Message, opts ...grpc.CallOption) (*ServerStream, error)
InvokeRpcServerStream sends a unary RPC and returns the response stream. Use this for server-streaming methods.
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.