v1

package
v1.0.14 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

type Client[REQ any, RESP any] interface {
	Endpoint() Endpoint[REQ, RESP]
}

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

type Decoder[ProtoResp, RESP any] func(ctx context.Context, resp ProtoResp) (RESP, error)

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

type Encoder[REQ, ProtoReq any] func(ctx context.Context, req REQ) (ProtoReq, error)

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.

func NewEndpoint

func NewEndpoint[REQ any, RESP any](ep endpoint.Endpoint) Endpoint[REQ, RESP]

NewEndpoint adapts a go-kit endpoint into a domain-typed Endpoint.

type GRPCRequest

type GRPCRequest[REQ any] struct {
	Metadata map[string][]string
	Body     REQ
}

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

type Middleware[REQ any, RESP any] func(Endpoint[REQ, RESP]) Endpoint[REQ, RESP]

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

type MockClient[REQ any, RESP any] struct {
	// contains filtered or unexported fields
}

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

type MockClientBuilder[REQ any, RESP any] struct {
	// contains filtered or unexported fields
}

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

type MockClientMockRecorder[REQ any, RESP any] struct {
	// contains filtered or unexported fields
}

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

type MsgExtractor[ProtoMsg any] func(msg ProtoMsg) []byte

MsgExtractor extracts the payload bytes from a streamed protobuf message. It is the client-side counterpart of the server framework's MsgAssembler.

type StreamDecoder

type StreamDecoder[RESP any] func(ctx context.Context, data []byte) (RESP, error)

StreamDecoder converts the fully aggregated streaming payload into a domain response. The transport layer concatenates all received chunks before calling it.

type StreamOpener

type StreamOpener[REQ any] func(ctx context.Context, req REQ) (grpc.ClientStream, error)

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.

Jump to

Keyboard shortcuts

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