memstore

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 12, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmptyMap          = errors.New("memstore: cannot select from an empty map")
	ErrEmptySlice        = errors.New("memstore: cannot select from an empty slice")
	ErrLenMismatch       = errors.New("memstore: cannot select from a map, not enough elements")
	ErrTeamNotFound      = errors.New("memstore: team not found")
	ErrUserNotSet        = errors.New("memstore: user is not set")
	ErrTeamStoreEmpty    = errors.New("memstore: team store is empty")
	ErrChannelStoreEmpty = errors.New("memstore: channel store is empty")
	ErrChannelNotFound   = errors.New("memstore: channel not found")
	ErrPostNotFound      = errors.New("memstore: post not found")
	ErrInvalidData       = errors.New("memstore: invalid data found")
)

Functions

func SetRandomSeed

func SetRandomSeed() int64

SetRandomSeed sets the global random seed and returns it's value.

Types

type CQueue

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

CQueue is a basic implementation of a circular queue of fixed size.

func NewCQueue

func NewCQueue(size int, newEl func() interface{}) (*CQueue, error)

NewCQueue creates and returns a pointer to a queue of the given size. The passed newEl parameter is a function used to allocate an element if data for it is not yet present in the queue.

func (*CQueue) Get

func (q *CQueue) Get() interface{}

Get returns a pointer to the next element in the queue. In case this is nil, data for it will be allocated before returning.

func (*CQueue) Reset

func (q *CQueue) Reset()

Reset re-initializes the queue to be reused.

type Config

type Config struct {
	MaxStoredPosts          int // The maximum number of posts to be stored.
	MaxStoredUsers          int // The maximum number of users to be stored.
	MaxStoredChannelMembers int // The maximum number of channel members to be stored.
	MaxStoredStatuses       int // The maximum number of statuses to be stored.
}

Config holds information used to create a new MemStore.

func (*Config) IsValid

func (c *Config) IsValid() error

IsValid checks whether a Config is valid or not. Returns an error if the validation fails.

func (*Config) SetDefaults

func (c *Config) SetDefaults()

SetDefaults sets default values to the config.

type MemStore

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

MemStore is a simple implementation of MutableUserStore which holds all data in memory.

func New

func New(config *Config) (*MemStore, error)

New returns a new instance of MemStore with the given config. If config is nil, defaults will be used.

func (*MemStore) Channel

func (s *MemStore) Channel(channelId string) (*model.Channel, error)

Channel returns the channel for the given channelId.

func (*MemStore) ChannelMember

func (s *MemStore) ChannelMember(channelId, userId string) (model.ChannelMember, error)

ChannelMember returns the channel member for the given channelId and userId.

func (*MemStore) ChannelMembers

func (s *MemStore) ChannelMembers(channelId string) (*model.ChannelMembers, error)

ChannelMembers returns a list of members for the specified channel.

func (*MemStore) ChannelPosts

func (s *MemStore) ChannelPosts(channelId string) ([]*model.Post, error)

ChannelPosts returns all posts for the specified channel.

func (*MemStore) ChannelPostsSorted

func (s *MemStore) ChannelPostsSorted(channelId string, asc bool) ([]*model.Post, error)

ChannelPostsSorted returns all posts for specified channel, sorted by CreateAt.

func (*MemStore) ChannelStats added in v1.3.0

func (s *MemStore) ChannelStats(channelId string) (*model.ChannelStats, error)

ChannelStats returns statistics for the given channelId.

func (*MemStore) ChannelView

func (s *MemStore) ChannelView(channelId string) (int64, error)

ChannelView returns the timestamp of the last view for the given channelId.

func (*MemStore) Channels

func (s *MemStore) Channels(teamId string) ([]model.Channel, error)

Channels returns all the channels for a team.

func (*MemStore) Clear

func (s *MemStore) Clear()

Clear resets the store and removes all entries with the exception of the user object and state information (current team/channel) which are preserved.

func (*MemStore) ClientConfig added in v1.3.0

func (s *MemStore) ClientConfig() map[string]string

ClientConfig returns the limited server configuration settings for user.

func (*MemStore) Config

func (s *MemStore) Config() model.Config

Config returns the server configuration settings.

func (*MemStore) CurrentChannel

func (s *MemStore) CurrentChannel() (*model.Channel, error)

GetCurrentChannel returns the channel the user is currently viewing.

func (*MemStore) CurrentTeam

func (s *MemStore) CurrentTeam() (*model.Team, error)

GetCurrentTeam returns the currently selected team for the user.

func (*MemStore) DeletePost

func (s *MemStore) DeletePost(postId string) error

DeletePost deletes the specified post.

func (*MemStore) DeleteReaction

func (s *MemStore) DeleteReaction(reaction *model.Reaction) (bool, error)

DeleteReaction deletes the given reaction. It returns whether or not the reaction was deleted.

func (*MemStore) Email

func (s *MemStore) Email() string

Email returns the email for the stored user.

func (*MemStore) FileInfoForPost

func (s *MemStore) FileInfoForPost(postId string) ([]*model.FileInfo, error)

FileInfoForPost returns the FileInfo for the specified post, if any.

func (*MemStore) GetUser

func (s *MemStore) GetUser(userId string) (model.User, error)

GetUser returns the user for the given userId.

func (*MemStore) Id

func (s *MemStore) Id() string

Id returns the id for the stored user.

func (*MemStore) Password

func (s *MemStore) Password() string

Password returns the password for the stored user.

func (*MemStore) Post

func (s *MemStore) Post(postId string) (*model.Post, error)

Post returns the post for the given postId.

func (*MemStore) PostsIdsSince

func (s *MemStore) PostsIdsSince(ts int64) ([]string, error)

PostsIdsSince returns a list of post ids for posts created after a specified timestamp in milliseconds.

func (*MemStore) Preferences

func (s *MemStore) Preferences() (model.Preferences, error)

Preferences returns the preferences for the stored user.

func (*MemStore) ProfileImage

func (s *MemStore) ProfileImage(userId string) (bool, error)

ProfileImage returns whether the profile image for the given user has been stored.

func (*MemStore) RandomChannel

func (s *MemStore) RandomChannel(teamId string, st store.SelectionType) (model.Channel, error)

RandomChannel returns a random channel for the given teamId for the current user.

func (*MemStore) RandomChannelMember

func (s *MemStore) RandomChannelMember(channelId string) (model.ChannelMember, error)

RandomChannelMember returns a random channel member for a channel.

func (*MemStore) RandomEmoji

func (s *MemStore) RandomEmoji() (model.Emoji, error)

RandomEmoji returns a random emoji.

func (*MemStore) RandomPost

func (s *MemStore) RandomPost() (model.Post, error)

RandomPost returns a random post.

func (*MemStore) RandomPostForChannel

func (s *MemStore) RandomPostForChannel(channelId string) (model.Post, error)

RandomPostForChannel returns a random post for the given channel.

func (*MemStore) RandomPostForChannelByUser

func (s *MemStore) RandomPostForChannelByUser(channelId, userId string) (model.Post, error)

RandomPostForChannelForUser returns a random post for the given channel made by the given user.

func (*MemStore) RandomTeam

func (s *MemStore) RandomTeam(st store.SelectionType) (model.Team, error)

RandomTeam returns a random team for the current user.

func (*MemStore) RandomTeamMember

func (s *MemStore) RandomTeamMember(teamId string) (model.TeamMember, error)

RandomTeamMember returns a random team member for a team.

func (*MemStore) RandomUser

func (s *MemStore) RandomUser() (model.User, error)

RandomUser returns a random user from the set of users.

func (*MemStore) RandomUsers

func (s *MemStore) RandomUsers(n int) ([]model.User, error)

RandomUsers returns N random users from the set of users.

func (*MemStore) Reactions

func (s *MemStore) Reactions(postId string) ([]model.Reaction, error)

Reactions returns the reactions for the specified post.

func (*MemStore) RemoveChannelMember

func (s *MemStore) RemoveChannelMember(channelId string, userId string) error

RemoveChannelMember removes the channel member for the specified channel and user.

func (*MemStore) RemoveTeamMember

func (s *MemStore) RemoveTeamMember(teamId string, userId string) error

RemoveTeamMember removes the team member for the specified team and user..

func (*MemStore) Roles

func (s *MemStore) Roles() ([]model.Role, error)

Roles returns the roles of the user.

func (*MemStore) ServerVersion added in v1.2.0

func (s *MemStore) ServerVersion() (string, error)

ServerVersion returns the server version string.

func (*MemStore) SetChannel

func (s *MemStore) SetChannel(channel *model.Channel) error

SetChannel stores the given channel.

func (*MemStore) SetChannelMember

func (s *MemStore) SetChannelMember(channelId string, channelMember *model.ChannelMember) error

SetChannelMember stores the given channel member.

func (*MemStore) SetChannelMembers

func (s *MemStore) SetChannelMembers(channelMembers *model.ChannelMembers) error

SetChannelMembers stores the given channel members in the store.

func (*MemStore) SetChannelStats added in v1.3.0

func (s *MemStore) SetChannelStats(channelId string, stats *model.ChannelStats) error

SetChannelStats stores statistics for the given channelId.

func (*MemStore) SetChannelView

func (s *MemStore) SetChannelView(channelId string) error

SetChannelView marks the given channel as viewed and updates the store with the current timestamp.

func (*MemStore) SetChannels

func (s *MemStore) SetChannels(channels []*model.Channel) error

SetChannels adds the given channels to the store.

func (*MemStore) SetClientConfig added in v1.3.0

func (s *MemStore) SetClientConfig(config map[string]string)

Set ClientConfig stores the given limited configuration settings.

func (*MemStore) SetConfig

func (s *MemStore) SetConfig(config *model.Config)

SetConfig stores the given configuration settings.

func (*MemStore) SetCurrentChannel

func (s *MemStore) SetCurrentChannel(channel *model.Channel) error

SetCurrentChannel stores the channel the user is currently viewing.

func (*MemStore) SetCurrentTeam

func (s *MemStore) SetCurrentTeam(team *model.Team) error

SetCurrentTeam sets the currently selected team for the user.

func (*MemStore) SetEmojis

func (s *MemStore) SetEmojis(emoji []*model.Emoji) error

SetEmojis stores the given emojis.

func (*MemStore) SetLicense

func (s *MemStore) SetLicense(license map[string]string) error

SetLicense stores the given license in the store.

func (*MemStore) SetPost

func (s *MemStore) SetPost(post *model.Post) error

SetPost stores the given post.

func (*MemStore) SetPosts

func (s *MemStore) SetPosts(posts []*model.Post) error

SetPosts stores the given posts.

func (*MemStore) SetPreferences

func (s *MemStore) SetPreferences(preferences *model.Preferences) error

Preferences stores the preferences for the stored user.

func (*MemStore) SetProfileImage

func (s *MemStore) SetProfileImage(userId string) error

SetProfileImage sets as stored the profile image for the given user.

func (*MemStore) SetReaction

func (s *MemStore) SetReaction(reaction *model.Reaction) error

SetReaction stores the given reaction.

func (*MemStore) SetReactions

func (s *MemStore) SetReactions(postId string, reactions []*model.Reaction) error

SetReactions stores the given reactions for the specified post.

func (*MemStore) SetRoles

func (s *MemStore) SetRoles(roles []*model.Role) error

SetRoles stores the given roles.

func (*MemStore) SetServerVersion added in v1.2.0

func (s *MemStore) SetServerVersion(version string) error

SetProfileImage sets as stored the profile image for the given user.

func (*MemStore) SetStatus

func (s *MemStore) SetStatus(userId string, status *model.Status) error

SetStatus stores the status for the given userId.

func (*MemStore) SetTeam

func (s *MemStore) SetTeam(team *model.Team) error

SetTeam stores the given team.

func (*MemStore) SetTeamMember

func (s *MemStore) SetTeamMember(teamId string, teamMember *model.TeamMember) error

SetTeamMember stores the given team member.

func (*MemStore) SetTeamMembers

func (s *MemStore) SetTeamMembers(teamId string, teamMembers []*model.TeamMember) error

SetTeamMembers stores the given team members.

func (*MemStore) SetTeams

func (s *MemStore) SetTeams(teams []*model.Team) error

SetTeams stores the given teams.

func (*MemStore) SetUser

func (s *MemStore) SetUser(user *model.User) error

SetUser stores the given user.

func (*MemStore) SetUsers

func (s *MemStore) SetUsers(users []*model.User) error

SetUsers stores the given users.

func (*MemStore) Status

func (s *MemStore) Status(userId string) (model.Status, error)

Status returns the status for the given userId.

func (*MemStore) Team

func (s *MemStore) Team(teamId string) (*model.Team, error)

Team returns the team for the given teamId.

func (*MemStore) TeamMember

func (s *MemStore) TeamMember(teamId, userId string) (model.TeamMember, error)

TeamMember returns the team member for the given teamId and userId.

func (*MemStore) Teams

func (s *MemStore) Teams() ([]model.Team, error)

Teams returns the teams a user belong to.

func (*MemStore) User

func (s *MemStore) User() (*model.User, error)

User returns the stored user.

func (*MemStore) UserForPost

func (s *MemStore) UserForPost(postId string) (string, error)

UserForPost returns the userId for the user who created the specified post.

func (*MemStore) Username

func (s *MemStore) Username() string

Username returns the username for the stored user.

func (*MemStore) UsersIdsForPostsIds

func (s *MemStore) UsersIdsForPostsIds(postIds []string) ([]string, error)

UsersIdsForPostsIds returns a list of user ids that created the specified posts.

Jump to

Keyboard shortcuts

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