Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2018 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	Users    UserCacher
	Channels ChannelCacher
	Guilds   GuildCacher // TODO: implement
	// contains filtered or unexported fields
}

func NewCache

func NewCache() *Cache

func (*Cache) Channel

func (st *Cache) Channel(ID Snowflake) (*resource.Channel, error)

func (*Cache) Clear

func (st *Cache) Clear()

func (*Cache) Close

func (st *Cache) Close() (err error)

https://golang.org/pkg/io/#Closer

func (*Cache) Guild

func (st *Cache) Guild(ID Snowflake) (*resource.Guild, error)

------ Guilds

func (*Cache) Myself

func (s *Cache) Myself() *resource.User

func (*Cache) ProcessChannel

func (st *Cache) ProcessChannel(details *ChannelDetail)

func (*Cache) ProcessGuild

func (st *Cache) ProcessGuild(gd *GuildDetail)

func (*Cache) ProcessUser

func (st *Cache) ProcessUser(details *UserDetail)

func (*Cache) User

func (st *Cache) User(ID Snowflake) (*resource.User, error)

----- Users

type Cacher

type Cacher interface {
	User(ID Snowflake) (*resource.User, error)
	Channel(ID Snowflake) (*resource.Channel, error)
	Guild(ID Snowflake) (*resource.Guild, error)
	Myself() *resource.User

	// clear all the cached objects
	Clear()
}

Cacher used by the session interface, so the user cannot access methods to ruin the cache state

type ChannelCache

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

func NewChannelCache

func NewChannelCache(userCacher ChannelUserCacher) *ChannelCache

func (*ChannelCache) Chan

func (st *ChannelCache) Chan() chan<- *ChannelDetail

func (*ChannelCache) Channel

func (st *ChannelCache) Channel(ID Snowflake) (*resource.Channel, error)

func (*ChannelCache) Clear

func (st *ChannelCache) Clear()

Clear empty the cache

func (*ChannelCache) Close

func (st *ChannelCache) Close() (err error)

func (*ChannelCache) Process

func (st *ChannelCache) Process(cd *ChannelDetail)

func (*ChannelCache) Size

func (st *ChannelCache) Size() int

type ChannelCacher

type ChannelCacher interface {
	Process(cd *ChannelDetail)
	Chan() chan<- *ChannelDetail
	Channel(ID Snowflake) (*resource.Channel, error)
	Size() int
	Clear()
	Close() error
}

type ChannelDetail

type ChannelDetail struct {
	Channel *resource.Channel
	Dirty   bool
	Action  string //event.* for specific behavior, such as delete
}

ChannelDetail holds information about the "incoming" channel object. how it was created, should it be considered dirty, etc.

type ChannelUserCacher

type ChannelUserCacher interface {
	Process(ud *UserDetail)
	User(ID Snowflake) (*resource.User, error)
}

type GuildCache

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

GuildCache handles guild caching

func NewGuildCache

func NewGuildCache(userCacher GuildUserCacher, channelCacher GuildChannelCacher) *GuildCache

NewGuildCache creates a new guild cacher, and starts listening for inputs

func (*GuildCache) Chan

func (st *GuildCache) Chan() chan<- *GuildDetail

func (*GuildCache) Clear

func (st *GuildCache) Clear()

Clear empty the cache

func (*GuildCache) Close

func (st *GuildCache) Close() (err error)

func (*GuildCache) Guild

func (st *GuildCache) Guild(ID Snowflake) (*resource.Guild, error)

func (*GuildCache) Process

func (st *GuildCache) Process(gd *GuildDetail)

type GuildCacher

type GuildCacher interface {
	Process(cd *GuildDetail)
	Chan() chan<- *GuildDetail
	Guild(ID Snowflake) (*resource.Guild, error)
	Clear()
	Close() error
}

type GuildChannelCacher

type GuildChannelCacher interface {
	Process(ud *ChannelDetail)
}

type GuildDetail

type GuildDetail struct {
	Guild  *resource.Guild
	Dirty  bool
	Action string // event type
}

type GuildUserCacher

type GuildUserCacher interface {
	Process(ud *UserDetail)
}

type UserCache

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

UserCache handles user caching

func NewUserCache

func NewUserCache() *UserCache

NewUserCache creates a new user cacher, and starts listening for inputs

func (*UserCache) Chan

func (st *UserCache) Chan() chan<- *UserDetail

func (*UserCache) Clear

func (st *UserCache) Clear()

Clear empty the cache

func (*UserCache) Close

func (st *UserCache) Close() (err error)

func (*UserCache) Process

func (st *UserCache) Process(uc *UserDetail)

func (*UserCache) Size

func (st *UserCache) Size() int

func (*UserCache) StartListener

func (st *UserCache) StartListener() (err error)

func (*UserCache) User

func (st *UserCache) User(ID Snowflake) (*resource.User, error)

User get a copy from the cache, which can be safely distributed without ruining the up to date discord cache. See st.updaterUser(...) for more information why it's a copy only.

type UserCacher

type UserCacher interface {
	Process(ud *UserDetail)
	Chan() chan<- *UserDetail
	User(ID Snowflake) (*resource.User, error)
	Size() int
	Clear()
	StartListener() error
	Close() error
}

type UserDetail

type UserDetail struct {
	User  *resource.User
	Dirty bool // if the user is a part of another struct, like Member, we only need to check that it exists. otherwise dirty.
}

UserCache made this a struct, in case I want to add details/data in the future for optimizing caching.

Jump to

Keyboard shortcuts

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