Documentation ¶
Index ¶
- Variables
- type Config
- type HA
- type HAInstance
- func (h *HAInstance) AddHandler(handler interface{}) func()
- func (h *HAInstance) AmLeader(ctx context.Context) bool
- func (h *HAInstance) CacheRead(cache, key string, want interface{}) (interface{}, error)
- func (h *HAInstance) CacheWrite(cache, key string, data interface{}, ttl time.Duration) error
- func (h *HAInstance) ElectLeader(ctx context.Context) error
- func (h *HAInstance) Lock(obj interface{}) (bool, string, error)
- func (h *HAInstance) LockVoice(moduleID, guildID string) (bool, error)
- func (h *HAInstance) ResignLeader(ctx context.Context) error
- func (h *HAInstance) SendVoiceCommand(command VoiceCommand) error
- func (h *HAInstance) Stop()
- func (h *HAInstance) Unlock(lockKey string) error
- func (h *HAInstance) UnlockVoice(moduleID, guildID string) error
- func (h *HAInstance) WatchVoiceCommands(ctx context.Context, moduleID string) chan VoiceCommand
- type VoiceCommand
Constants ¶
This section is empty.
Variables ¶
var ErrorCacheKeyNotExist = errors.New("Cache key does not exist")
ErrorCacheKeyNotExist is the error the cache returns if a key does not exist
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { Session *discordgo.Session HA bool LockUpdateInterval time.Duration LockTTL time.Duration EtcdEndpoints []string Context context.Context Log log.Logger VerboseLevel int DoNotParticipateInLeaderElection bool }
Config contains the configuration for HA
type HA ¶
type HA interface { // AddHandler makes a discordgo handler HA, it will only be ran on one replica AddHandler(handler interface{}) func() // CacheRead allows to read a cached object from etcd shared across all replicas CacheRead(cache, key string, want interface{}) (interface{}, error) // CacheWrite allows to read a cached object from etcd shared across all replicas CacheWrite(cache, key string, data interface{}, ttl time.Duration) error // Stop should be run when the program terminates Stop() // LockVoice locks a voice channel for a specific module and Guild, returns true if successful, this function may change soon! LockVoice(moduleID, guildID string) (bool, error) // LockVoice locks a voice channel for a specific module and Guild, this function may change soon! UnlockVoice(moduleID, guildID string) error // SendVoiceCommand sends a string command to the instance handling the voice channel // These can be received using WatchVoiceCommands // this function may change soon! SendVoiceCommand(command VoiceCommand) error // WatchVoiceCommands gives a channel with commands transmitted by SendVoiceCommand // this function may change soon! WatchVoiceCommands(ctx context.Context, moduleID string) chan VoiceCommand }
type HAInstance ¶
type HAInstance struct {
// contains filtered or unexported fields
}
HA is a helper struct for high available discordgo using etcd
func (*HAInstance) AddHandler ¶
func (h *HAInstance) AddHandler(handler interface{}) func()
func (*HAInstance) CacheRead ¶
func (h *HAInstance) CacheRead(cache, key string, want interface{}) (interface{}, error)
CacheRead reads a key from a specific cache, returns ErrorCacheKeyNotExist if not found
func (*HAInstance) CacheWrite ¶
func (h *HAInstance) CacheWrite(cache, key string, data interface{}, ttl time.Duration) error
CacheWrite writes an object to a specific cache with a specific key, will be purged after TTL expires
func (*HAInstance) ElectLeader ¶
func (h *HAInstance) ElectLeader(ctx context.Context) error
func (*HAInstance) Lock ¶
func (h *HAInstance) Lock(obj interface{}) (bool, string, error)
Lock tries to acquire a lock on an event, it will return true if the instance that requests it may process the request.
func (*HAInstance) LockVoice ¶
func (h *HAInstance) LockVoice(moduleID, guildID string) (bool, error)
LockVoice locks a voice channel ID, returns true if successful
func (*HAInstance) ResignLeader ¶
func (h *HAInstance) ResignLeader(ctx context.Context) error
func (*HAInstance) SendVoiceCommand ¶
func (h *HAInstance) SendVoiceCommand(command VoiceCommand) error
SendVoiceCommand sends a string command to the instance handling the voice channel These can be received using WatchVoiceCommands
func (*HAInstance) Stop ¶
func (h *HAInstance) Stop()
Stop should be run when the program terminates
func (*HAInstance) Unlock ¶
func (h *HAInstance) Unlock(lockKey string) error
Unlock will release a lock on an event
func (*HAInstance) UnlockVoice ¶
func (h *HAInstance) UnlockVoice(moduleID, guildID string) error
UnlockVoice unlocks a voice channel ID
func (*HAInstance) WatchVoiceCommands ¶
func (h *HAInstance) WatchVoiceCommands(ctx context.Context, moduleID string) chan VoiceCommand
WatchVoiceCommands gives a channel with commands transmitted by SendVoiceCommand for a specifid ModuleID