Documentation ¶
Index ¶
- Constants
- Variables
- type Attachment
- type Cache
- func (c *Cache) Attachment(at *discordgo.MessageAttachment) (Attachment, error)
- func (c *Cache) Channel(ID string) (discordgo.Channel, error)
- func (c *Cache) Clean()
- func (c *Cache) Guild(ID string) (discordgo.Guild, error)
- func (c *Cache) InvalidateChannel(ID string) error
- func (c *Cache) InvalidateGuild(ID string) error
- func (c *Cache) InvalidateUser(ID string) error
- func (c *Cache) User(ID string) (discordgo.User, error)
- type Provider
Constants ¶
const ( // Approximate maximum lifetime an attachment can live for without being cleaned up. AttachmentLifetime = time.Minute * 5 // Threshold at which the attachments cache will begin to prune excess elements. AttachmentPruneThreshold = 1000 )
Cache cleanup constants.
Variables ¶
var ( ErrMissing = errors.New("cache: entry not present") ErrNilProvider = errors.New("cache: attempted to create cache with nil provider") ErrIO = errors.New("cache: attachment download: I/O error") ErrRequest = errors.New("cache: attachment download: network request failed") ErrGetFailed = errors.New("cache: attachment download: http error") )
Generic errors.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
An Attachment is a generic representation for an attachment downloaded from the Discord API.
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache represents a cache of Discord API data objects.
func (*Cache) Attachment ¶
func (c *Cache) Attachment(at *discordgo.MessageAttachment) (Attachment, error)
Attachment looks up and returns the content and info for a remote attachment from the Discord API. Lookups from the same url are guaranteed not to cause an API hit. Errors are not cached and the attachment is assumed to not exist.
func (*Cache) Channel ¶
Channel looks up and returns a channel's data from the discord API, or returns the cached value if already found. If the channel could not be found, error is returned from the discord API. Errors are not cached and failed lookups cause a new API hit.
func (*Cache) Clean ¶
func (c *Cache) Clean()
Clean walks the cache, freeing any bulky cached items which are deemed not particularly useful (e.g attachments which have not been reused in a while).
func (*Cache) Guild ¶
Guild looks up and returns a guild's data from the discord API, or returns the cached value if already found. If the guild could not be found, error is returned from the discord API. Errors are not cached and failed lookups cause a new API hit.
func (*Cache) InvalidateChannel ¶
InvalidateChannel invalidates the cache entry for a given channel ID.
func (*Cache) InvalidateGuild ¶
InvalidateGuild invalidates the cache entry for a given guild ID.
func (*Cache) InvalidateUser ¶
InvalidateUser invalidates the cache entry for a given user ID.
type Provider ¶
type Provider interface { Channel(channelID string) (c *discordgo.Channel, err error) User(userID string) (u *discordgo.User, err error) Guild(guildID string) (st *discordgo.Guild, err error) }
Provider is a data provider for discord users and channels. This is mainly for testing and is designed for use with either a mock or *discordgo.Session.