Documentation
¶
Overview ¶
Package pool runs and multiplexes many bots by token over a single process, lazily starting a Bot per token and garbage-collecting idle ones.
It is the multi-bot front end for github.com/gotd/botapi: a local Bot API server, or any service that serves many bots, can hold one Pool and call Do with a token to borrow a connected Bot.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Options ¶
type Options struct {
// AppID and AppHash are the shared MTProto app identity used for every bot
// (https://my.telegram.org). Required.
AppID int
AppHash string
// Logger is the base structured logger (github.com/gotd/log port).
// Defaults to a no-op logger.
Logger log.Logger
// StateDir, when set, is the directory holding each bot's persistent session
// file (<id>.bbolt). When empty, bots run with in-memory storage and nothing
// survives a restart.
StateDir string
// IdleTimeout shuts down a bot that has not been borrowed for this long.
// Zero disables idle collection (RunGC then does nothing).
IdleTimeout time.Duration
}
Options configures a Pool.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool is a concurrency-safe set of bots keyed by token.
func (*Pool) Do ¶
Do borrows the running bot for token, starting and authorizing it on first use, and invokes fn with it. It blocks until the bot is ready, fn returns, or ctx is canceled. A failure to start the bot is returned to every concurrent caller waiting on it.