Documentation
¶
Overview ¶
Package interceptor provides decorators for tg.Invoker to sniff, augment, and control MTProto operations.
Index ¶
- Variables
- func IsOutgoing(ctx context.Context) bool
- func OutgoingPeer(ctx context.Context) tg.InputPeerClass
- func WithOutgoing(ctx context.Context) context.Context
- func WithOutgoingPeer(ctx context.Context, peer tg.InputPeerClass) context.Context
- type BoundedFloodWaiter
- type DispatcherFunc
- type InMemoryLimiter
- type Limiter
- type OutgoingInterceptor
- type RateLimiter
- type TelemetryExtractor
Constants ¶
This section is empty.
Variables ¶
var ErrFloodShedding = errors.New("tgbox: request dropped due to flood wait saturation (load shedding)")
ErrFloodShedding is returned when an MTProto request is dropped due to excessive flood wait saturation.
Functions ¶
func IsOutgoing ¶
IsOutgoing checks if the context originates from an outgoing (self-sent) call.
func OutgoingPeer ¶ added in v0.2.0
func OutgoingPeer(ctx context.Context) tg.InputPeerClass
OutgoingPeer retrieves the target input peer from the context if present.
func WithOutgoing ¶
WithOutgoing marks the context as originating from an outgoing (self-sent) call.
func WithOutgoingPeer ¶ added in v0.2.0
WithOutgoingPeer associates the destination input peer with an outgoing request context.
Types ¶
type BoundedFloodWaiter ¶
type BoundedFloodWaiter struct {
// contains filtered or unexported fields
}
BoundedFloodWaiter retries requests that hit FLOOD_WAIT errors, but only up to a bounded number of retries and a bounded wait duration; beyond either threshold the request is dropped with ErrFloodShedding.
func NewBoundedFloodWaiter ¶
func NewBoundedFloodWaiter(maxRetries uint, maxWait time.Duration) *BoundedFloodWaiter
NewBoundedFloodWaiter creates the flood-wait middleware. A zero maxRetries or maxWait disables that specific limit.
func (*BoundedFloodWaiter) Handle ¶
func (w *BoundedFloodWaiter) Handle(next tg.Invoker) telegram.InvokeFunc
Handle wraps the standard tg.Invoker with backoff and shedding capabilities.
func (*BoundedFloodWaiter) WithClock ¶
func (w *BoundedFloodWaiter) WithClock(c clock.Clock) *BoundedFloodWaiter
WithClock sets a custom clock for the BoundedFloodWaiter (essential for virtual clock testing).
type DispatcherFunc ¶
type DispatcherFunc func(context.Context, tg.UpdatesClass) error
DispatcherFunc defines the callback signature to inject synthetic updates back into the pipeline.
type InMemoryLimiter ¶
type InMemoryLimiter struct {
// contains filtered or unexported fields
}
InMemoryLimiter implements a local token bucket limiter using golang.org/x/time/rate.
func NewInMemoryLimiter ¶
func NewInMemoryLimiter(rateLimit rate.Limit, burst int) *InMemoryLimiter
NewInMemoryLimiter creates a local token-bucket limiter that refills rateLimit tokens per second with the given maximum burst.
type Limiter ¶
type Limiter interface {
// Wait blocks until the limiter permits execution or the context is canceled.
Wait(ctx context.Context) error
}
Limiter abstracts a rate-limiting strategy, allowing local (in-memory) and distributed (e.g. Redis) backends to be used interchangeably.
type OutgoingInterceptor ¶
type OutgoingInterceptor struct {
// contains filtered or unexported fields
}
OutgoingInterceptor wraps a tg.Invoker to intercept outgoing message/media methods, emit synthetic UpdatesClass payloads, and trace network latencies via OpenTelemetry.
func NewOutgoingInterceptor ¶
func NewOutgoingInterceptor(next tg.Invoker, dispatch DispatcherFunc, extractor TelemetryExtractor) *OutgoingInterceptor
NewOutgoingInterceptor creates a new decorator over a base tg.Invoker with telemetry support.
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter wraps tg.Invoker to throttle outgoing RPC calls before hitting Telegram servers.
func NewRateLimiter ¶
func NewRateLimiter(limiter Limiter) *RateLimiter
NewRateLimiter instantiates a new MTProto rate limiter middleware.
func (*RateLimiter) Handle ¶
func (r *RateLimiter) Handle(next tg.Invoker) telegram.InvokeFunc
Handle intercepts the execution pipeline and enforces the rate limit rules.