Documentation
¶
Overview ¶
Package procframe provides a proto-driven typed handler runtime.
It defines transport-independent abstractions for requests, responses, streaming, and handlers across all four RPC shapes (unary, client-stream, server-stream, bidi). Procedure handlers return ordinary Go errors; transports map those errors to structured statuses at the boundary. Code generation from proto definitions produces handler interfaces and transport glue for CLI, Connect/gRPC (HTTP), and WebSocket; this package supplies the minimal runtime kernel that the generated code builds on.
Index ¶
- func InvokeBidi[Req, Res any](ctx context.Context, spec CallSpec, stream BidiStream[Req, Res], ...) error
- func InvokeServerStream[Req, Res any](ctx context.Context, spec CallSpec, req *Request[Req], ...) error
- type AnyRequest
- type AnyResponse
- type BidiStream
- type BidiStreamHandler
- type CallShape
- type CallSpec
- type ClientStream
- type ClientStreamHandler
- type Code
- type Conn
- type ErrorMapper
- type HandlerFunc
- type Interceptor
- type InterceptorFunc
- type Meta
- type Request
- type Response
- type ServerStream
- type ServerStreamHandler
- type Status
- type StatusError
- type Transport
- type UnaryHandler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InvokeBidi ¶
func InvokeBidi[Req, Res any]( ctx context.Context, spec CallSpec, stream BidiStream[Req, Res], handler func(context.Context, BidiStream[Req, Res]) error, interceptors ...Interceptor, ) error
InvokeBidi executes a typed bidi-stream handler through the interceptor chain.
func InvokeServerStream ¶
func InvokeServerStream[Req, Res any]( ctx context.Context, spec CallSpec, req *Request[Req], stream ServerStream[Res], handler func(context.Context, *Request[Req], ServerStream[Res]) error, interceptors ...Interceptor, ) error
InvokeServerStream executes a typed server-stream handler through the interceptor chain.
Types ¶
type AnyRequest ¶
AnyRequest is the middleware-facing request view.
type AnyResponse ¶
AnyResponse is the middleware-facing response view.
func NewAnyResponse ¶
func NewAnyResponse(msg any) AnyResponse
NewAnyResponse constructs a middleware-visible response from an arbitrary message.
func NewAnyResponseWithMeta ¶
func NewAnyResponseWithMeta(msg any, meta Meta) AnyResponse
NewAnyResponseWithMeta constructs a middleware-visible response with explicit metadata.
type BidiStream ¶
type BidiStream[Req, Res any] interface { Context() context.Context Receive() (*Request[Req], error) Send(*Response[Res]) error }
BidiStream is the server-side interface for bidirectional streaming. It supports both receiving requests and sending responses concurrently. Concrete implementations are provided by each transport.
type BidiStreamHandler ¶
type BidiStreamHandler[Req, Res any] interface { HandleBidi(context.Context, BidiStream[Req, Res]) error }
BidiStreamHandler handles a bidirectional stream of requests and responses.
type ClientStream ¶
ClientStream is the server-side interface for receiving a sequence of requests from the caller. Concrete implementations are provided by each transport.
type ClientStreamHandler ¶
type ClientStreamHandler[Req, Res any] interface { Handle(context.Context, ClientStream[Req]) (*Response[Res], error) }
ClientStreamHandler handles a stream of requests and returns a single response.
type Conn ¶
type Conn interface {
Context() context.Context
Spec() CallSpec
Receive() (AnyRequest, error)
Send(AnyResponse) error
}
Conn is the generic connection surface seen by middleware. It provides shape-independent Receive/Send operations. Middleware composes behavior by wrapping a Conn and delegating Receive/Send to the inner Conn (the conn-decorator pattern).
type ErrorMapper ¶
ErrorMapper maps an error to a transport-facing Status. It returns false when the error should remain unclassified.
type HandlerFunc ¶
HandlerFunc is the generic handler invocation shape used by middleware.
type Interceptor ¶
type Interceptor interface {
Wrap(HandlerFunc) HandlerFunc
}
Interceptor composes cross-cutting behavior around handler execution.
type InterceptorFunc ¶
type InterceptorFunc func(HandlerFunc) HandlerFunc
InterceptorFunc is a function that implements Interceptor.
func (InterceptorFunc) Wrap ¶
func (f InterceptorFunc) Wrap(next HandlerFunc) HandlerFunc
type Response ¶
Response wraps a typed message with transport-independent metadata.
func InvokeClientStream ¶
func InvokeClientStream[Req, Res any]( ctx context.Context, spec CallSpec, stream ClientStream[Req], handler func(context.Context, ClientStream[Req]) (*Response[Res], error), interceptors ...Interceptor, ) (*Response[Res], error)
InvokeClientStream executes a typed client-stream handler through the interceptor chain.
func InvokeUnary ¶
func InvokeUnary[Req, Res any]( ctx context.Context, spec CallSpec, req *Request[Req], handler func(context.Context, *Request[Req]) (*Response[Res], error), interceptors ...Interceptor, ) (*Response[Res], error)
InvokeUnary executes a typed unary handler through the interceptor chain.
type ServerStream ¶
ServerStream is the server-side interface for sending a sequence of responses back to the caller. Concrete implementations are provided by each transport (e.g. transport/cli).
type ServerStreamHandler ¶
type ServerStreamHandler[Req, Res any] interface { HandleStream(context.Context, *Request[Req], ServerStream[Res]) error }
ServerStreamHandler handles a single request and writes zero or more responses to the provided ServerStream.
type StatusError ¶
type StatusError struct {
// contains filtered or unexported fields
}
StatusError is the default structured error wrapper provided by procframe.
func Errorf ¶
func Errorf(code Code, format string, args ...any) *StatusError
Errorf creates a StatusError with a formatted message.
func NewError ¶
func NewError(code Code, msg string) *StatusError
NewError creates a StatusError with the given code and message.
func WrapError ¶
func WrapError(code Code, msg string, cause error) *StatusError
WrapError creates a StatusError that wraps a cause error.
func (*StatusError) Error ¶
func (e *StatusError) Error() string
Error returns a string in the form "<code>: <message>". The cause is intentionally omitted; use errors.Unwrap to traverse the chain.
func (*StatusError) IsRetryable ¶
func (e *StatusError) IsRetryable() bool
IsRetryable reports whether the caller may retry the operation.
func (*StatusError) Message ¶
func (e *StatusError) Message() string
Message returns the human-readable error message.
func (*StatusError) Status ¶
func (e *StatusError) Status() *Status
Status returns the transport-facing status carried by the error.
func (*StatusError) Unwrap ¶
func (e *StatusError) Unwrap() error
Unwrap returns the underlying cause so that errors.Is and errors.As work through the error chain.
func (*StatusError) WithRetryable ¶
func (e *StatusError) WithRetryable() *StatusError
WithRetryable returns a copy of e with the retryable flag set to true.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
protoc-gen-procframe-go
command
Command protoc-gen-procframe-go is a protoc plugin that generates handler interfaces and CLI runner code from service definitions annotated with procframe options.
|
Command protoc-gen-procframe-go is a protoc plugin that generates handler interfaces and CLI runner code from service definitions annotated with procframe options. |
|
examples
|
|
|
gen
|
|
|
internal
|
|
|
codegen
Package gen implements code generation for protoc-gen-procframe-go.
|
Package gen implements code generation for protoc-gen-procframe-go. |
|
transport
|
|
|
connect
Package connect provides a Connect protocol transport for procframe services.
|
Package connect provides a Connect protocol transport for procframe services. |