flood

package
v0.1.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CondHandler added in v0.0.3

type CondHandler struct {
	// contains filtered or unexported fields
}

This handler uses sync.Cond for flood handling. It has additional overhead of memory and locking. Flood is handled in separate for each api method.

func NewCondHandler added in v0.0.3

func NewCondHandler(onFlood OnFloodFunc) *CondHandler

func (*CondHandler) Enter added in v0.0.3

func (c *CondHandler) Enter(ctx context.Context, method string, request any)

func (*CondHandler) Handle added in v0.0.3

func (c *CondHandler) Handle(
	ctx context.Context,
	method string,
	request any,
	duration time.Duration,
)

type Handler

type Handler interface {
	Enter(
		ctx context.Context,
		method string,
		request any,
	) // Gets called BEFORE making an api request
	Handle(
		ctx context.Context,
		method string,
		request any,
		duration time.Duration,
	) // Gets called when 429 error happens
}

Interface for flood handlers. See `flood.CondHandler` or `flood.SleepHandler`. Or write one yourself.

type OnFloodFunc added in v0.0.3

type OnFloodFunc func(ctx context.Context, method string, request any, duration time.Duration)

type SleepHandler

type SleepHandler struct {
	OnFlood OnFloodFunc // Optional callback that will be called before sleeping
}

Dummy flood handler. It will just sleep for the flood duration.

See `flood.CondHandler`.

func (*SleepHandler) Enter

func (s *SleepHandler) Enter(context.Context, string, any)

func (*SleepHandler) Handle

func (s *SleepHandler) Handle(
	ctx context.Context,
	method string,
	request any,
	duration time.Duration,
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL