Documentation
¶
Overview ¶
Package v1 provides a generic gRPC client SDK mirroring the HTTP client SDK (pkg/client-sdk/http/v1). It exposes a domain-typed, unary-only Client[REQ, RESP] built through a fluent ClientBuilder with composable middlewares.
Protocol encoding is injected (Encoder/Decoder) rather than automatic, matching the gRPC server framework's generic contracts. Server-streaming RPCs are handled transparently by the transport layer: StreamRecvMsg aggregates all chunks into a complete payload, which the endpoint forwards to the caller as a single unary response, so client users consume the service layer without stream awareness.
Channel-based streaming (a channel-driven receive primitive and a service-layer streaming client) is planned; see the TODO(channel-transport) markers.
Package v1 is a generated GoMock package.
Index ¶
- func StreamRecvMsg[ProtoMsg any](stream grpc.ClientStream, extractor MsgExtractor[ProtoMsg]) ([]byte, error)
- type Client
- type ClientBuilder
- func NewStreamClientBuilder[REQ, RESP, ProtoMsg any](conn *grpc.ClientConn, service, method string, opener StreamOpener[REQ], ...) ClientBuilder[REQ, RESP]
- func NewUnaryClientBuilder[REQ, RESP, ProtoReq, ProtoResp any](conn *grpc.ClientConn, service, method string, encoder Encoder[REQ, ProtoReq], ...) ClientBuilder[REQ, RESP]
- type Decoder
- type Encoder
- type Endpoint
- type GRPCRequest
- type Middleware
- type MockClient
- type MockClientBuilder
- func (m *MockClientBuilder[REQ, RESP]) Build() Client[REQ, RESP]
- func (m *MockClientBuilder[REQ, RESP]) EXPECT() *MockClientBuilderMockRecorder[REQ, RESP]
- func (m *MockClientBuilder[REQ, RESP]) Use(middleware Middleware[REQ, RESP]) ClientBuilder[REQ, RESP]
- func (m *MockClientBuilder[REQ, RESP]) UseMany(middlewares ...Middleware[REQ, RESP]) ClientBuilder[REQ, RESP]
- func (m *MockClientBuilder[REQ, RESP]) WithOptions(options ...grpc.ClientOption) ClientBuilder[REQ, RESP]
- type MockClientBuilderMockRecorder
- func (mr *MockClientBuilderMockRecorder[REQ, RESP]) Build() *gomock.Call
- func (mr *MockClientBuilderMockRecorder[REQ, RESP]) Use(middleware any) *gomock.Call
- func (mr *MockClientBuilderMockRecorder[REQ, RESP]) UseMany(middlewares ...any) *gomock.Call
- func (mr *MockClientBuilderMockRecorder[REQ, RESP]) WithOptions(options ...any) *gomock.Call
- type MockClientMockRecorder
- type MsgExtractor
- type StreamDecoder
- type StreamOpener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func StreamRecvMsg ¶
func StreamRecvMsg[ProtoMsg any](stream grpc.ClientStream, extractor MsgExtractor[ProtoMsg]) ([]byte, error)
StreamRecvMsg receives all messages from a server stream and concatenates their extracted payloads into a complete byte slice. It hides the chunked transport from the caller: io.EOF terminates the loop and returns the aggregated data. ProtoMsg must be a pointer to a protobuf message (e.g. *pbv1.Chunk).
Types ¶
type Client ¶
Client provides a domain-typed endpoint with request/response conversion. It mirrors the HTTP SDK's Client; server-streaming RPCs are exposed as unary responses.
func NewStreamClient ¶
func NewStreamClient[REQ, RESP, ProtoMsg any]( conn *grpc.ClientConn, service, method string, opener StreamOpener[REQ], extractor MsgExtractor[ProtoMsg], decoder StreamDecoder[RESP], options ...grpctransport.ClientOption, ) Client[REQ, RESP]
NewStreamClient creates a server-streaming gRPC client exposed as a unary endpoint.
func NewUnaryClient ¶
func NewUnaryClient[REQ, RESP, ProtoReq, ProtoResp any]( conn *grpc.ClientConn, service, method string, encoder Encoder[REQ, ProtoReq], decoder Decoder[ProtoResp, RESP], reply ProtoResp, options ...grpctransport.ClientOption, ) Client[REQ, RESP]
NewUnaryClient creates a unary gRPC client with optional go-kit client options.
type ClientBuilder ¶
type ClientBuilder[REQ any, RESP any] interface { Use(middleware Middleware[REQ, RESP]) ClientBuilder[REQ, RESP] UseMany(middlewares ...Middleware[REQ, RESP]) ClientBuilder[REQ, RESP] WithOptions(options ...grpctransport.ClientOption) ClientBuilder[REQ, RESP] Build() Client[REQ, RESP] }
ClientBuilder is the fluent builder for a gRPC client.
func NewStreamClientBuilder ¶
func NewStreamClientBuilder[REQ, RESP, ProtoMsg any]( conn *grpc.ClientConn, service, method string, opener StreamOpener[REQ], extractor MsgExtractor[ProtoMsg], decoder StreamDecoder[RESP], ) ClientBuilder[REQ, RESP]
NewStreamClientBuilder creates a builder for a server-streaming RPC. The transport layer aggregates all chunks (StreamRecvMsg) and decodes the full payload, so the resulting Client behaves as a unary endpoint.
func NewUnaryClientBuilder ¶
func NewUnaryClientBuilder[REQ, RESP, ProtoReq, ProtoResp any]( conn *grpc.ClientConn, service, method string, encoder Encoder[REQ, ProtoReq], decoder Decoder[ProtoResp, RESP], reply ProtoResp, ) ClientBuilder[REQ, RESP]
NewUnaryClientBuilder creates a builder for a unary RPC with injected codecs.
type Decoder ¶
Decoder converts a protobuf response message to a domain response. It is the client-side counterpart of the server framework's Encoder. ProtoResp: protobuf response type; RESP: domain response type.
type Encoder ¶
Encoder converts a domain request to a protobuf request message. It is the client-side counterpart of the server framework's Decoder. REQ: domain request type; ProtoReq: protobuf request type.
type Endpoint ¶
type Endpoint[REQ any, RESP any] func(ctx context.Context, request GRPCRequest[REQ]) (response RESP, err error)
Endpoint is the domain-typed client endpoint. It mirrors the HTTP SDK's Endpoint.
type GRPCRequest ¶
GRPCRequest carries the outgoing gRPC metadata (headers) and the domain request body. It is the gRPC counterpart of the HTTP SDK's HTTPRequest.
type Middleware ¶
Middleware wraps an Endpoint and returns a new Endpoint.
func Chain ¶
func Chain[REQ any, RESP any](middlewares ...Middleware[REQ, RESP]) Middleware[REQ, RESP]
Chain applies multiple middlewares in order (first middleware wraps outermost).
type MockClient ¶
MockClient is a mock of Client interface.
func NewMockClient ¶
func NewMockClient[REQ any, RESP any](ctrl *gomock.Controller) *MockClient[REQ, RESP]
NewMockClient creates a new mock instance.
func (*MockClient[REQ, RESP]) EXPECT ¶
func (m *MockClient[REQ, RESP]) EXPECT() *MockClientMockRecorder[REQ, RESP]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockClient[REQ, RESP]) Endpoint ¶
func (m *MockClient[REQ, RESP]) Endpoint() Endpoint[REQ, RESP]
Endpoint mocks base method.
type MockClientBuilder ¶
MockClientBuilder is a mock of ClientBuilder interface.
func NewMockClientBuilder ¶
func NewMockClientBuilder[REQ any, RESP any](ctrl *gomock.Controller) *MockClientBuilder[REQ, RESP]
NewMockClientBuilder creates a new mock instance.
func (*MockClientBuilder[REQ, RESP]) Build ¶
func (m *MockClientBuilder[REQ, RESP]) Build() Client[REQ, RESP]
Build mocks base method.
func (*MockClientBuilder[REQ, RESP]) EXPECT ¶
func (m *MockClientBuilder[REQ, RESP]) EXPECT() *MockClientBuilderMockRecorder[REQ, RESP]
EXPECT returns an object that allows the caller to indicate expected use.
func (*MockClientBuilder[REQ, RESP]) Use ¶
func (m *MockClientBuilder[REQ, RESP]) Use(middleware Middleware[REQ, RESP]) ClientBuilder[REQ, RESP]
Use mocks base method.
func (*MockClientBuilder[REQ, RESP]) UseMany ¶
func (m *MockClientBuilder[REQ, RESP]) UseMany(middlewares ...Middleware[REQ, RESP]) ClientBuilder[REQ, RESP]
UseMany mocks base method.
func (*MockClientBuilder[REQ, RESP]) WithOptions ¶
func (m *MockClientBuilder[REQ, RESP]) WithOptions(options ...grpc.ClientOption) ClientBuilder[REQ, RESP]
WithOptions mocks base method.
type MockClientBuilderMockRecorder ¶
type MockClientBuilderMockRecorder[REQ any, RESP any] struct { // contains filtered or unexported fields }
MockClientBuilderMockRecorder is the mock recorder for MockClientBuilder.
func (*MockClientBuilderMockRecorder[REQ, RESP]) Build ¶
func (mr *MockClientBuilderMockRecorder[REQ, RESP]) Build() *gomock.Call
Build indicates an expected call of Build.
func (*MockClientBuilderMockRecorder[REQ, RESP]) Use ¶
func (mr *MockClientBuilderMockRecorder[REQ, RESP]) Use(middleware any) *gomock.Call
Use indicates an expected call of Use.
func (*MockClientBuilderMockRecorder[REQ, RESP]) UseMany ¶
func (mr *MockClientBuilderMockRecorder[REQ, RESP]) UseMany(middlewares ...any) *gomock.Call
UseMany indicates an expected call of UseMany.
func (*MockClientBuilderMockRecorder[REQ, RESP]) WithOptions ¶
func (mr *MockClientBuilderMockRecorder[REQ, RESP]) WithOptions(options ...any) *gomock.Call
WithOptions indicates an expected call of WithOptions.
type MockClientMockRecorder ¶
MockClientMockRecorder is the mock recorder for MockClient.
func (*MockClientMockRecorder[REQ, RESP]) Endpoint ¶
func (mr *MockClientMockRecorder[REQ, RESP]) Endpoint() *gomock.Call
Endpoint indicates an expected call of Endpoint.
type MsgExtractor ¶
MsgExtractor extracts the payload bytes from a streamed protobuf message. It is the client-side counterpart of the server framework's MsgAssembler.
type StreamDecoder ¶
StreamDecoder converts the fully aggregated streaming payload into a domain response. The transport layer concatenates all received chunks before calling it.
type StreamOpener ¶
StreamOpener opens a server-streaming RPC and returns the client stream. The concrete opener is generated by the protobuf client (e.g. DemoClient.Download), whose stream type embeds grpc.ClientStream.