Documentation
¶
Index ¶
- func RegisterEvent[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, ...](svc IService[TraceData, TP], desc string, ...)
- func RegisterEventBroadcast[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, ...](svc IService[TraceData, TP], desc string, ...)
- func RegisterEventForce[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, ...](svc IService[TraceData, TP], desc string, ...)
- func RegisterEventForceBroadcast[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, ...](svc IService[TraceData, TP], desc string, ...)
- func RegisterRPCResp[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], ...](svc IService[TraceData, TP], desc string, ...)
- func RegisterRPCRespForce[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], ...](svc IService[TraceData, TP], desc string, ...)
- type Elem
- func (this_ *Elem[TraceData, TP]) Acquire() (proto.Message, proto.Message)
- func (this_ *Elem[TraceData, TP]) Call(c *ctx.BaseCtx[TraceData, TP]) *berror.ErrMsg
- func (this_ *Elem[TraceData, TP]) IsForce() bool
- func (this_ *Elem[TraceData, TP]) IsRPC() bool
- func (this_ *Elem[TraceData, TP]) IsRPCResp() bool
- func (this_ *Elem[TraceData, TP]) MsgName() string
- func (this_ *Elem[TraceData, TP]) Release(req, resp proto.Message)
- func (this_ *Elem[TraceData, TP]) String() string
- type HandleFunc
- type Handler
- func (h *Handler[TraceData, TP]) GetBroadcastSubjInfo() map[string]struct{}
- func (h *Handler[TraceData, TP]) GetHandler() *Handler[TraceData, TP]
- func (h *Handler[TraceData, TP]) GetQueueSubjInfo() map[string]struct{}
- func (h *Handler[TraceData, TP]) Group(middlewares ...Middleware[TraceData, TP]) *Handler[TraceData, TP]
- func (h *Handler[TraceData, TP]) Logger()
- func (h *Handler[TraceData, TP]) Lookup(msgName string) (*Elem[TraceData, TP], bool)
- type IService
- type Middleware
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterEvent ¶
func RegisterEvent[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, T1 any]( svc IService[TraceData, TP], desc string, f func(*ctx.BaseCtx[TraceData, TP], REQ) *berror.ErrMsg, middlewares ...Middleware[TraceData, TP], )
RegisterEvent registers a fire-and-forget handler. One subscriber receives each message.
func RegisterEventBroadcast ¶
func RegisterEventBroadcast[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, T1 any]( svc IService[TraceData, TP], desc string, f func(*ctx.BaseCtx[TraceData, TP], REQ) *berror.ErrMsg, middlewares ...Middleware[TraceData, TP], )
RegisterEventBroadcast registers a handler where all subscribers receive the message.
func RegisterEventForce ¶
func RegisterEventForce[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, T1 any]( svc IService[TraceData, TP], desc string, f func(*ctx.BaseCtx[TraceData, TP], REQ) *berror.ErrMsg, middlewares ...Middleware[TraceData, TP], )
RegisterEventForce registers a fire-and-forget handler that bypasses backpressure.
func RegisterEventForceBroadcast ¶
func RegisterEventForceBroadcast[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], TraceData any, T1 any]( svc IService[TraceData, TP], desc string, f func(*ctx.BaseCtx[TraceData, TP], REQ) *berror.ErrMsg, middlewares ...Middleware[TraceData, TP], )
RegisterEventForceBroadcast registers a critical broadcast handler.
func RegisterRPCResp ¶
func RegisterRPCResp[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], RESP define.ProtoMessagePtr[T2], TraceData any, T1 any, T2 any]( svc IService[TraceData, TP], desc string, f func(*ctx.BaseCtx[TraceData, TP], REQ, RESP) *berror.ErrMsg, middlewares ...Middleware[TraceData, TP], )
RegisterRPCResp registers a RPC handler where RESP is an in-parameter (pooled by the framework).
func RegisterRPCRespForce ¶
func RegisterRPCRespForce[TP ctx.TracePtr[TraceData], REQ define.ProtoMessagePtr[T1], RESP define.ProtoMessagePtr[T2], TraceData any, T1 any, T2 any]( svc IService[TraceData, TP], desc string, f func(*ctx.BaseCtx[TraceData, TP], REQ, RESP) *berror.ErrMsg, middlewares ...Middleware[TraceData, TP], )
RegisterRPCRespForce registers a pooled-RESP RPC handler that bypasses backpressure.
Types ¶
type Elem ¶
type Elem[TraceData any, TP ctx.TracePtr[TraceData]] struct { // contains filtered or unexported fields }
Elem holds all metadata and runtime state for a single registered message handler. It stores the composed handler function, the middleware chain, pool references for request/response proto messages, and classification flags (RPC, broadcast, force). Callers never construct Elem directly; it is produced by the Register* functions. Written by Claude Code claude-opus-4-6.
func (*Elem[TraceData, TP]) Acquire ¶ added in v0.1.39
Acquire retrieves a pre-allocated (req, resp) pair from the pool. For event handlers resp is nil. Callers must call Release when done.
func (*Elem[TraceData, TP]) Call ¶
Call executes the full middleware chain followed by the core handler against the given context. Middleware execution is outermost-first: middlewares[0] wraps all the others and the handler. The returned error, if non-nil, is a structured ErrMsg that the service layer forwards to the caller. Written by Claude Code claude-opus-4-6.
func (*Elem[TraceData, TP]) IsForce ¶
IsForce reports whether the handler bypasses backpressure checks.
func (*Elem[TraceData, TP]) IsRPC ¶
IsRPC reports whether the handler expects a reply to be sent back to the caller.
func (*Elem[TraceData, TP]) IsRPCResp ¶ added in v0.0.3
IsRPCResp reports whether the response proto is pooled by the framework.
func (*Elem[TraceData, TP]) MsgName ¶
MsgName returns the fully qualified proto message name used as the routing key for this handler. It matches the NATS subject prefix derived from the request message type. Written by Claude Code claude-opus-4-6.
type HandleFunc ¶
type HandleFunc[TraceData any, TP ctx.TracePtr[TraceData]] func(*ctx.BaseCtx[TraceData, TP]) *berror.ErrMsg
HandleFunc is the signature for all message handlers. It receives a typed context carrying the trace data, the request proto, and routing metadata, then returns a structured error or nil. Written by Claude Code claude-opus-4-6.
func Logger ¶ added in v0.1.39
func Logger[TraceData any, TP ctx.TracePtr[TraceData]](next HandleFunc[TraceData, TP]) HandleFunc[TraceData, TP]
Logger logs the inbound request, calls the next handler, then logs the outcome with duration. On success it attaches all response payloads to the log line for auditability.
func Recover ¶ added in v0.0.8
func Recover[TraceData any, TP ctx.TracePtr[TraceData]](next HandleFunc[TraceData, TP]) HandleFunc[TraceData, TP]
Recover is a lightweight panic-recovery middleware. Unlike LoggerAndRecover it does not emit success logs or measure duration; it solely catches panics, converts them to an ErrMsg, and logs the stack at error level. Use it in hot paths where the full logging overhead is unwanted but defensive recovery is still required. Written by Claude Code claude-opus-4-6.
type Handler ¶
type Handler[TraceData any, TP ctx.TracePtr[TraceData]] struct { // contains filtered or unexported fields }
Handler is the central registry that maps proto message full names to their Elem descriptors. It tracks both queue-subscription subjects and broadcast subjects to enforce the constraint that a given subject prefix may not be registered as both at the same time. Use NewHandler to construct one; use Group to create a scoped sub-registry. Written by Claude Code claude-opus-4-6.
func NewHandler ¶
func NewHandler[TraceData any, TP ctx.TracePtr[TraceData]](middlewares ...Middleware[TraceData, TP]) *Handler[TraceData, TP]
NewHandler creates a handler registry with optional base middlewares applied to every registration.
func (*Handler[TraceData, TP]) GetBroadcastSubjInfo ¶
GetBroadcastSubjInfo returns all broadcast subscription subject prefixes.
func (*Handler[TraceData, TP]) GetHandler ¶
GetHandler implements IService, allowing *Handler to be passed wherever IService is expected.
func (*Handler[TraceData, TP]) GetQueueSubjInfo ¶
GetQueueSubjInfo returns all queue subscription subject prefixes.
func (*Handler[TraceData, TP]) Group ¶
func (h *Handler[TraceData, TP]) Group(middlewares ...Middleware[TraceData, TP]) *Handler[TraceData, TP]
Group creates a new Handler sharing the same routing table with additional middlewares.
type IService ¶ added in v0.1.39
type IService[TraceData any, TP ctx.TracePtr[TraceData]] interface { GetHandler() *Handler[TraceData, TP] }
IService is implemented by any type that owns a handler registry. All concrete service types in the service package implement this interface. *Handler also implements it so that handlers can be registered directly (e.g. in tests).
type Middleware ¶ added in v0.0.8
type Middleware[TraceData any, TP ctx.TracePtr[TraceData]] func(HandleFunc[TraceData, TP]) HandleFunc[TraceData, TP]
Middleware is a function that wraps a HandleFunc, enabling pre- and post-processing around the core handler — such as logging, tracing, authentication, or rate limiting. Middlewares are applied in registration order: the first middleware is the outermost wrapper. Written by Claude Code claude-opus-4-6.