Documentation
¶
Index ¶
- Variables
- func IsTimeoutErr(err error) bool
- func ReleaseCtx(ctx *CtxImpl)
- func ReleaseRequest(ctx *RequestImpl)
- func ReleaseResponse(ctx *ResponseImpl)
- type Client
- type ClientImpl
- func (c *ClientImpl) Close()
- func (c *ClientImpl) NewRequest() Request
- func (c *ClientImpl) ReleaseRequest(req Request)
- func (c *ClientImpl) ReleaseResponse(resp Response)
- func (c *ClientImpl) SendEvent(ctx context.Context, req Request) error
- func (c *ClientImpl) SendRequest(ctx context.Context, req Request) (Response, error)
- type Ctx
- type CtxImpl
- func (c *CtxImpl) Body() []byte
- func (c *CtxImpl) GetHeader(key, defaultValue string) string
- func (c *CtxImpl) Headers() [][]byte
- func (c *CtxImpl) Locals() Locals
- func (c *CtxImpl) Method() []byte
- func (c *CtxImpl) SetBody(buff []byte)
- func (c *CtxImpl) SetCode(code uint32)
- func (c *CtxImpl) SetHeader(key, value string)
- func (c *CtxImpl) SetHeaders(buff [][]byte)
- type EventCtx
- type Locals
- type LocalsImpl
- type QRPCServerImpl
- type QRpcServer
- type Request
- type RequestImpl
- func (c *RequestImpl) Body() []byte
- func (c *RequestImpl) Headers() [][]byte
- func (c *RequestImpl) Locals() Locals
- func (c *RequestImpl) Method() []byte
- func (c *RequestImpl) Req() *gen.Request
- func (c *RequestImpl) RequestId() uint64
- func (c *RequestImpl) SetBody(b []byte)
- func (c *RequestImpl) SetHeaders(h [][]byte)
- func (c *RequestImpl) SetMethod(m []byte)
- type Response
- type ResponseImpl
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClientClosed is returned when attempting to use a closed client. ErrClientClosed = errors.New("client is closed") )
var TimeoutDuration = time.Second * 30
TimeoutDuration is the write deadline applied to stream operations. It defaults to 30 seconds.
Functions ¶
func IsTimeoutErr ¶
IsTimeoutErr checks whether the given error is a QUIC idle timeout error.
func ReleaseRequest ¶
func ReleaseRequest(ctx *RequestImpl)
ReleaseRequest returns a RequestImpl to the pool for reuse.
func ReleaseResponse ¶
func ReleaseResponse(ctx *ResponseImpl)
ReleaseResponse returns a ResponseImpl to the pool for reuse.
Types ¶
type Client ¶
type Client interface {
NewRequest() Request
SendRequest(ctx context.Context, req Request) (Response, error)
ReleaseResponse(resp Response)
SendEvent(ctx context.Context, req Request) error
ReleaseRequest(req Request)
Close()
}
Client is the qrpc client interface for sending RPC requests and one-way events over QUIC connections. Implementations use stream multiplexing, object pooling, and a sharded concurrent map for request-response dispatch.
type ClientImpl ¶
type ClientImpl struct {
// contains filtered or unexported fields
}
ClientImpl is the concrete implementation of Client. It manages multiple QUIC connections, stream multiplexers, and response channels.
func (*ClientImpl) Close ¶
func (c *ClientImpl) Close()
Close gracefully shuts down the client, waits for pending requests, and closes all multiplexers and QUIC connections.
func (*ClientImpl) NewRequest ¶
func (c *ClientImpl) NewRequest() Request
NewRequest obtains a pooled Request wrapping a protobuf Request message.
func (*ClientImpl) ReleaseRequest ¶
func (c *ClientImpl) ReleaseRequest(req Request)
ReleaseRequest returns a Request to the pool for reuse.
func (*ClientImpl) ReleaseResponse ¶
func (c *ClientImpl) ReleaseResponse(resp Response)
ReleaseResponse returns a Response to the pool for reuse.
func (*ClientImpl) SendEvent ¶
func (c *ClientImpl) SendEvent( ctx context.Context, req Request, ) error
SendEvent sends a one-way event with no response expected. The request is released back to the pool after sending.
func (*ClientImpl) SendRequest ¶
SendRequest sends an RPC request and waits for a response. The request is released back to the pool after sending.
type Ctx ¶
type Ctx interface {
Locals() Locals
Body() []byte
Headers() [][]byte
Method() []byte
SetBody(buff []byte)
SetHeaders(buff [][]byte)
GetHeader(key, defaultValue string) string
SetHeader(key, value string)
SetCode(code uint32)
}
Ctx is the context passed to RPC handlers. It provides read access to the incoming request and write access to the response.
type CtxImpl ¶
type CtxImpl struct {
// contains filtered or unexported fields
}
CtxImpl is the concrete implementation of Ctx and EventCtx. It wraps a protobuf Request and Response and is pooled via sync.Pool.
func (*CtxImpl) SetHeaders ¶
type EventCtx ¶
type EventCtx interface {
Locals() Locals
Body() []byte
Headers() [][]byte
GetHeader(key, defaultValue string) string
Method() []byte
}
EventCtx is the context passed to event handlers. It provides read-only access to the event — no response is sent.
type Locals ¶
type Locals interface {
SetString(key, value string)
GetString(key string) string
Set(key string, value any)
Get(key string) any
Reset()
}
Locals is a per-request local storage for passing arbitrary data between middlewares and handlers.
type LocalsImpl ¶
type LocalsImpl struct {
// contains filtered or unexported fields
}
LocalsImpl is the concrete implementation of Locals with separate maps for string and arbitrary values, protected by an RWMutex.
func (*LocalsImpl) Get ¶
func (l *LocalsImpl) Get(key string) any
func (*LocalsImpl) GetString ¶
func (l *LocalsImpl) GetString(key string) string
func (*LocalsImpl) Reset ¶
func (l *LocalsImpl) Reset()
func (*LocalsImpl) Set ¶
func (l *LocalsImpl) Set(key string, value any)
func (*LocalsImpl) SetString ¶
func (l *LocalsImpl) SetString(key, value string)
type QRPCServerImpl ¶
type QRPCServerImpl struct {
// contains filtered or unexported fields
}
QRPCServerImpl is the concrete implementation of QRpcServer. It listens on a QUIC address, accepts streams, and dispatches requests and events to the registered handlers.
func (*QRPCServerImpl) AddEventHandler ¶
func (s *QRPCServerImpl) AddEventHandler(method string, handler func(EventCtx))
AddEventHandler registers a one-way event handler for the given method name.
func (*QRPCServerImpl) AddHandler ¶
func (s *QRPCServerImpl) AddHandler(method string, handler func(Ctx))
AddHandler registers an RPC handler for the given method name.
type QRpcServer ¶
type QRpcServer interface {
AddHandler(method string, handler func(Ctx))
AddEventHandler(method string, handler func(EventCtx))
// contains filtered or unexported methods
}
QRpcServer is the server interface for registering RPC and event handlers and accepting QUIC connections.
type Request ¶
type Request interface {
Locals() Locals
Body() []byte
SetBody([]byte)
Headers() [][]byte
SetHeaders([][]byte)
Method() []byte
SetMethod([]byte)
RequestId() uint64
}
Request is the client-side request interface for setting method, body, headers, and accessing per-request local storage.
type RequestImpl ¶
type RequestImpl struct {
// contains filtered or unexported fields
}
RequestImpl wraps a protobuf Request and provides the Request interface.
func NewRequest ¶
func NewRequest(req *gen.Request) *RequestImpl
NewRequest wraps a protobuf Request in a pooled RequestImpl.
func (*RequestImpl) Body ¶
func (c *RequestImpl) Body() []byte
func (*RequestImpl) Headers ¶
func (c *RequestImpl) Headers() [][]byte
func (*RequestImpl) Locals ¶
func (c *RequestImpl) Locals() Locals
func (*RequestImpl) Method ¶
func (c *RequestImpl) Method() []byte
func (*RequestImpl) Req ¶
func (c *RequestImpl) Req() *gen.Request
func (*RequestImpl) RequestId ¶
func (c *RequestImpl) RequestId() uint64
func (*RequestImpl) SetBody ¶
func (c *RequestImpl) SetBody(b []byte)
func (*RequestImpl) SetHeaders ¶
func (c *RequestImpl) SetHeaders(h [][]byte)
func (*RequestImpl) SetMethod ¶
func (c *RequestImpl) SetMethod(m []byte)
type Response ¶
Response is the client-side response interface for reading the response body, headers, status code, and matching request ID.
type ResponseImpl ¶
type ResponseImpl struct {
// contains filtered or unexported fields
}
ResponseImpl wraps a protobuf Response and provides the Response interface.
func NewResponse ¶
func NewResponse(resp *gen.Response) *ResponseImpl
NewResponse wraps a protobuf Response in a pooled ResponseImpl.
func (*ResponseImpl) Body ¶
func (c *ResponseImpl) Body() []byte
func (*ResponseImpl) Code ¶
func (c *ResponseImpl) Code() uint32
func (*ResponseImpl) Headers ¶
func (c *ResponseImpl) Headers() [][]byte
func (*ResponseImpl) RequestId ¶
func (c *ResponseImpl) RequestId() uint64
func (*ResponseImpl) Resp ¶
func (c *ResponseImpl) Resp() *gen.Response