Documentation
¶
Overview ¶
Package request provides a fluent builder for constructing and executing gRPC requests. It handles JSON marshaling/unmarshaling, metadata management, and timeout configuration.
Index ¶
- type Builder
- func (req *Builder) AppendMetadata(k string, v ...string) *Builder
- func (req *Builder) ApplicationId(appId int) *Builder
- func (req *Builder) Do(ctx context.Context) error
- func (req *Builder) JsonRequestBody(reqBody any) *Builder
- func (req *Builder) JsonResponseBody(respPtr any) *Builder
- func (req *Builder) Timeout(timeout time.Duration) *Builder
- type Middleware
- type RoundTripper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Builder ¶
Builder provides a fluent API for constructing and executing gRPC requests. It handles JSON marshaling, metadata management, and timeout configuration. Builder is not safe for concurrent use; create a new instance for each request.
func NewBuilder ¶
func NewBuilder(roundTripper RoundTripper, endpoint string) *Builder
NewBuilder creates a new Builder for the specified endpoint. Initializes with default timeout and empty metadata.
func (*Builder) AppendMetadata ¶
AppendMetadata adds one or more values to the metadata key. Returns the Builder for method chaining.
func (*Builder) ApplicationId ¶
ApplicationId sets the application identity header for the request. Returns the Builder for method chaining.
func (*Builder) Do ¶
Do executes the request and unmarshals the response if a response pointer was provided. Returns an error if JSON marshaling, request execution, or response unmarshaling fails. Automatically applies the configured timeout to the request context.
func (*Builder) JsonRequestBody ¶
JsonRequestBody sets the request body as a JSON-encodable value. Returns the Builder for method chaining.
func (*Builder) JsonResponseBody ¶
JsonResponseBody sets the pointer to unmarshal the JSON response into. Returns the Builder for method chaining.
type Middleware ¶
type Middleware func(next RoundTripper) RoundTripper
Middleware wraps a RoundTripper to add cross-cutting concerns like logging, metrics, authentication, or error handling. Middleware functions are typically chained in reverse order of execution.
type RoundTripper ¶
type RoundTripper func(ctx context.Context, builder *Builder, message *isp.Message) (*isp.Message, error)
RoundTripper defines the interface for executing gRPC requests. Receives a context, request builder, and message; returns a response message and optional error. Used as the base for middleware chains.