Documentation
¶
Index ¶
- func ShardIDByGuild(guildID snowflake.ID, shardCount int) int
- func ShardMaxConcurrencyKey(shardID int, maxConcurrency int) int
- type Config
- type ConfigOpt
- func WithAutoScaling(autoScaling bool) ConfigOpt
- func WithGatewayConfigOpts(opts ...gateway.ConfigOpt) ConfigOpt
- func WithGatewayCreateFunc(gatewayCreateFunc gateway.CreateFunc) ConfigOpt
- func WithLogger(logger log.Logger) ConfigOpt
- func WithRateLimiter(rateLimiter RateLimiter) ConfigOpt
- func WithRateRateLimiterConfigOpt(opts ...RateLimiterConfigOpt) ConfigOpt
- func WithShardCount(shardCount int) ConfigOpt
- func WithShardIDs(shardIDs ...int) ConfigOpt
- func WithShardSplitCount(shardSplitCount int) ConfigOpt
- type RateLimiter
- type RateLimiterConfig
- type RateLimiterConfigOpt
- type ShardManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ShardIDByGuild ¶
ShardIDByGuild returns the shard ID for the given guildID and shardCount.
func ShardMaxConcurrencyKey ¶ added in v0.12.0
ShardMaxConcurrencyKey returns the bucket the given shardID with maxConcurrency belongs to.
Types ¶
type Config ¶
type Config struct {
Logger log.Logger
ShardIDs map[int]struct{}
ShardCount int
ShardSplitCount int
AutoScaling bool
GatewayCreateFunc gateway.CreateFunc
GatewayConfigOpts []gateway.ConfigOpt
RateLimiter RateLimiter
RateRateLimiterConfigOpts []RateLimiterConfigOpt
}
Config lets you configure your ShardManager instance.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a Config with sensible defaults.
type ConfigOpt ¶
type ConfigOpt func(config *Config)
ConfigOpt is a type alias for a function that takes a Config and is used to configure your Server.
func WithAutoScaling ¶ added in v0.11.0
WithAutoScaling sets whether the ShardManager should automatically re-shard shards if they are too large.
func WithGatewayConfigOpts ¶
WithGatewayConfigOpts lets you configure the gateway.Gateway created by the ShardManager.
func WithGatewayCreateFunc ¶
func WithGatewayCreateFunc(gatewayCreateFunc gateway.CreateFunc) ConfigOpt
WithGatewayCreateFunc sets the function which is used by the ShardManager to create a new gateway.Gateway.
func WithLogger ¶
WithLogger sets the logger of the ShardManager.
func WithRateLimiter ¶
func WithRateLimiter(rateLimiter RateLimiter) ConfigOpt
WithRateLimiter lets you inject your own srate.RateLimiter into the ShardManager.
func WithRateRateLimiterConfigOpt ¶ added in v0.12.0
func WithRateRateLimiterConfigOpt(opts ...RateLimiterConfigOpt) ConfigOpt
WithRateRateLimiterConfigOpt lets you configure the default srate.RateLimiter used by the ShardManager.
func WithShardCount ¶
WithShardCount sets the shard count of the ShardManager.
func WithShardIDs ¶ added in v0.12.0
WithShardIDs sets the shardIDs the ShardManager should manage.
func WithShardSplitCount ¶ added in v0.11.0
WithShardSplitCount sets the count a shard should be split into if it is too large. This is only used if AutoScaling is enabled.
type RateLimiter ¶ added in v0.12.0
type RateLimiter interface {
// Close gracefully closes the RateLimiter.
// If the context deadline is exceeded, the RateLimiter will be closed immediately.
Close(ctx context.Context)
// WaitBucket waits for the given shardID bucket to be available for new logins.
// If the context deadline is exceeded, WaitBucket will return immediately and no login will be attempted.
WaitBucket(ctx context.Context, shardID int) error
// UnlockBucket unlocks the given shardID bucket.
UnlockBucket(shardID int)
}
RateLimiter limits how many shards can log in to Discord at the same time.
func NewNoopRateLimiter ¶ added in v0.15.1
func NewNoopRateLimiter() RateLimiter
NewNoopRateLimiter creates a new noop RateLimiter.
func NewRateLimiter ¶ added in v0.12.0
func NewRateLimiter(opts ...RateLimiterConfigOpt) RateLimiter
NewRateLimiter creates a new default RateLimiter with the given RateLimiterConfigOpt(s).
type RateLimiterConfig ¶ added in v0.12.0
RateLimiterConfig lets you configure your RateLimiter instance.
func DefaultRateLimiterConfig ¶ added in v0.12.0
func DefaultRateLimiterConfig() *RateLimiterConfig
DefaultRateLimiterConfig returns a RateLimiterConfig with sensible defaults.
func (*RateLimiterConfig) Apply ¶ added in v0.12.0
func (c *RateLimiterConfig) Apply(opts []RateLimiterConfigOpt)
Apply applies the given RateLimiterConfigOpt(s) to the RateLimiterConfig
type RateLimiterConfigOpt ¶ added in v0.12.0
type RateLimiterConfigOpt func(config *RateLimiterConfig)
RateLimiterConfigOpt is a type alias for a function that takes a RateLimiterConfig and is used to configure your Server.
func WithMaxConcurrency ¶ added in v0.12.0
func WithMaxConcurrency(maxConcurrency int) RateLimiterConfigOpt
WithMaxConcurrency sets the maximum number of concurrent identifies in 5 seconds.
func WithRateLimiterLogger ¶ added in v0.12.0
func WithRateLimiterLogger(logger log.Logger) RateLimiterConfigOpt
WithRateLimiterLogger sets the logger for the RateLimiter.
type ShardManager ¶
type ShardManager interface {
// Open opens all configured shards.
Open(ctx context.Context)
// Close closes all shards.
Close(ctx context.Context)
// OpenShard opens a specific shard.
OpenShard(ctx context.Context, shardID int) error
// CloseShard closes a specific shard.
CloseShard(ctx context.Context, shardID int)
// ShardByGuildID returns the gateway.Gateway for the shard that contains the given guild.
ShardByGuildID(guildId snowflake.ID) gateway.Gateway
// Shard returns the gateway.Gateway for the given shard ID.
Shard(shardID int) gateway.Gateway
// Shards returns a copy of all shards as a map.
Shards() map[int]gateway.Gateway
}
ShardManager manages multiple gateway.Gateway connections. For more information on sharding see: https://discord.com/developers/docs/topics/gateway#sharding
func New ¶
func New(token string, eventHandlerFunc gateway.EventHandlerFunc, opts ...ConfigOpt) ShardManager
New creates a new default ShardManager with the given token, eventHandlerFunc and ConfigOpt(s).