Documentation ¶
Index ¶
- Variables
- func SortFeedbacks(feedback []Feedback)
- type Database
- type Feedback
- type FeedbackKey
- type Item
- type ItemPatch
- type MongoDB
- func (db *MongoDB) BatchGetItems(itemIds []string) ([]Item, error)
- func (db *MongoDB) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error
- func (db *MongoDB) BatchInsertItems(items []Item) error
- func (db *MongoDB) BatchInsertUsers(users []User) error
- func (db *MongoDB) Close() error
- func (db *MongoDB) CountActiveUsers(date time.Time) (int, error)
- func (db *MongoDB) DeleteItem(itemId string) error
- func (db *MongoDB) DeleteUser(userId string) error
- func (db *MongoDB) DeleteUserItemFeedback(userId, itemId string, feedbackTypes ...string) (int, error)
- func (db *MongoDB) GetFeedback(cursor string, n int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error)
- func (db *MongoDB) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error)
- func (db *MongoDB) GetItem(itemId string) (item Item, err error)
- func (db *MongoDB) GetItemFeedback(itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (db *MongoDB) GetItemStream(batchSize int, timeLimit *time.Time) (chan []Item, chan error)
- func (db *MongoDB) GetItems(cursor string, n int, timeLimit *time.Time) (string, []Item, error)
- func (db *MongoDB) GetUser(userId string) (user User, err error)
- func (db *MongoDB) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error)
- func (db *MongoDB) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (db *MongoDB) GetUserStream(batchSize int) (chan []User, chan error)
- func (db *MongoDB) GetUsers(cursor string, n int) (string, []User, error)
- func (db *MongoDB) Init() error
- func (db *MongoDB) ModifyItem(itemId string, patch ItemPatch) error
- func (db *MongoDB) ModifyUser(userId string, patch UserPatch) error
- func (db *MongoDB) Optimize() error
- type NoDatabase
- func (NoDatabase) BatchGetItems(_ []string) ([]Item, error)
- func (NoDatabase) BatchInsertFeedback(_ []Feedback, _, _, _ bool) error
- func (NoDatabase) BatchInsertItems(_ []Item) error
- func (NoDatabase) BatchInsertUsers(_ []User) error
- func (NoDatabase) Close() error
- func (NoDatabase) DeleteItem(_ string) error
- func (NoDatabase) DeleteUser(_ string) error
- func (NoDatabase) DeleteUserItemFeedback(_, _ string, _ ...string) (int, error)
- func (NoDatabase) GetFeedback(_ string, _ int, _ *time.Time, _ ...string) (string, []Feedback, error)
- func (NoDatabase) GetFeedbackStream(_ int, _ *time.Time, _ ...string) (chan []Feedback, chan error)
- func (NoDatabase) GetItem(_ string) (Item, error)
- func (NoDatabase) GetItemFeedback(_ string, _ ...string) ([]Feedback, error)
- func (NoDatabase) GetItemStream(_ int, _ *time.Time) (chan []Item, chan error)
- func (NoDatabase) GetItems(_ string, _ int, _ *time.Time) (string, []Item, error)
- func (NoDatabase) GetUser(_ string) (User, error)
- func (NoDatabase) GetUserFeedback(_ string, _ bool, _ ...string) ([]Feedback, error)
- func (NoDatabase) GetUserItemFeedback(_, _ string, _ ...string) ([]Feedback, error)
- func (NoDatabase) GetUserStream(_ int) (chan []User, chan error)
- func (NoDatabase) GetUsers(_ string, _ int) (string, []User, error)
- func (NoDatabase) Init() error
- func (d NoDatabase) ModifyItem(_ string, _ ItemPatch) error
- func (d NoDatabase) ModifyUser(_ string, _ UserPatch) error
- func (NoDatabase) Optimize() error
- type Redis
- func (r *Redis) BatchGetItems(itemIds []string) ([]Item, error)
- func (r *Redis) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error
- func (r *Redis) BatchInsertItems(items []Item) error
- func (r *Redis) BatchInsertUsers(users []User) error
- func (r *Redis) Close() error
- func (r *Redis) DeleteItem(itemId string) error
- func (r *Redis) DeleteUser(userId string) error
- func (r *Redis) DeleteUserItemFeedback(userId, itemId string, feedbackTypes ...string) (int, error)
- func (r *Redis) ForFeedback(ctx context.Context, ...) error
- func (r *Redis) GetFeedback(_ string, _ int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error)
- func (r *Redis) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error)
- func (r *Redis) GetItem(itemId string) (Item, error)
- func (r *Redis) GetItemFeedback(itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (r *Redis) GetItemStream(batchSize int, timeLimit *time.Time) (chan []Item, chan error)
- func (r *Redis) GetItems(cursor string, n int, timeLimit *time.Time) (string, []Item, error)
- func (r *Redis) GetUser(userId string) (User, error)
- func (r *Redis) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error)
- func (r *Redis) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (r *Redis) GetUserStream(batchSize int) (chan []User, chan error)
- func (r *Redis) GetUsers(cursor string, n int) (string, []User, error)
- func (r *Redis) Init() error
- func (r *Redis) ModifyItem(itemId string, patch ItemPatch) error
- func (r *Redis) ModifyUser(userId string, patch UserPatch) error
- func (r *Redis) Optimize() error
- type SQLDatabase
- func (d *SQLDatabase) BatchGetItems(itemIds []string) ([]Item, error)
- func (d *SQLDatabase) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error
- func (d *SQLDatabase) BatchInsertItems(items []Item) error
- func (d *SQLDatabase) BatchInsertUsers(users []User) error
- func (d *SQLDatabase) Close() error
- func (d *SQLDatabase) DeleteItem(itemId string) error
- func (d *SQLDatabase) DeleteUser(userId string) error
- func (d *SQLDatabase) DeleteUserItemFeedback(userId, itemId string, feedbackTypes ...string) (int, error)
- func (d *SQLDatabase) GetFeedback(cursor string, n int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error)
- func (d *SQLDatabase) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error)
- func (d *SQLDatabase) GetItem(itemId string) (Item, error)
- func (d *SQLDatabase) GetItemFeedback(itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (d *SQLDatabase) GetItemStream(batchSize int, timeLimit *time.Time) (chan []Item, chan error)
- func (d *SQLDatabase) GetItems(cursor string, n int, timeLimit *time.Time) (string, []Item, error)
- func (d *SQLDatabase) GetUser(userId string) (User, error)
- func (d *SQLDatabase) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error)
- func (d *SQLDatabase) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
- func (d *SQLDatabase) GetUserStream(batchSize int) (chan []User, chan error)
- func (d *SQLDatabase) GetUsers(cursor string, n int) (string, []User, error)
- func (d *SQLDatabase) Init() error
- func (d *SQLDatabase) ModifyItem(itemId string, patch ItemPatch) error
- func (d *SQLDatabase) ModifyUser(userId string, patch UserPatch) error
- func (d *SQLDatabase) Optimize() error
- type SQLDriver
- type User
- type UserPatch
Constants ¶
This section is empty.
Variables ¶
Functions ¶
Types ¶
type Database ¶
type Database interface { Init() error Close() error Optimize() error BatchInsertItems(items []Item) error BatchGetItems(itemIds []string) ([]Item, error) DeleteItem(itemId string) error GetItem(itemId string) (Item, error) ModifyItem(itemId string, patch ItemPatch) error GetItems(cursor string, n int, timeLimit *time.Time) (string, []Item, error) GetItemFeedback(itemId string, feedbackTypes ...string) ([]Feedback, error) BatchInsertUsers(users []User) error DeleteUser(userId string) error GetUser(userId string) (User, error) ModifyUser(userId string, patch UserPatch) error GetUsers(cursor string, n int) (string, []User, error) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error) DeleteUserItemFeedback(userId, itemId string, feedbackTypes ...string) (int, error) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error GetFeedback(cursor string, n int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error) GetUserStream(batchSize int) (chan []User, chan error) GetItemStream(batchSize int, timeLimit *time.Time) (chan []Item, chan error) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error) }
type Feedback ¶
type Feedback struct { FeedbackKey Timestamp time.Time Comment string }
Feedback stores feedback.
type FeedbackKey ¶
FeedbackKey identifies feedback.
func (*FeedbackKey) TableName ¶
func (*FeedbackKey) TableName() string
type Item ¶
type Item struct { ItemId string `gorm:"primaryKey"` IsHidden bool Categories []string `gorm:"serializer:json"` Timestamp time.Time Labels []string `gorm:"serializer:json"` Comment string }
Item stores meta data about item.
type ItemPatch ¶
type ItemPatch struct { IsHidden *bool Categories []string Timestamp *time.Time Labels []string Comment *string }
ItemPatch is the modification on an item.
type MongoDB ¶
type MongoDB struct {
// contains filtered or unexported fields
}
MongoDB is the data storage based on MongoDB.
func (*MongoDB) BatchInsertFeedback ¶
func (db *MongoDB) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error
BatchInsertFeedback returns multiple feedback into MongoDB.
func (*MongoDB) BatchInsertItems ¶
BatchInsertItems insert items into MongoDB.
func (*MongoDB) BatchInsertUsers ¶
BatchInsertUsers inserts a user into MongoDB.
func (*MongoDB) CountActiveUsers ¶
CountActiveUsers returns the number active users starting from a specified date.
func (*MongoDB) DeleteItem ¶
DeleteItem deletes a item from MongoDB.
func (*MongoDB) DeleteUser ¶
DeleteUser deletes a user from MongoDB.
func (*MongoDB) DeleteUserItemFeedback ¶
func (db *MongoDB) DeleteUserItemFeedback(userId, itemId string, feedbackTypes ...string) (int, error)
DeleteUserItemFeedback deletes a feedback return the user id and item id from MongoDB.
func (*MongoDB) GetFeedback ¶
func (db *MongoDB) GetFeedback(cursor string, n int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error)
GetFeedback returns multiple feedback from MongoDB.
func (*MongoDB) GetFeedbackStream ¶
func (db *MongoDB) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error)
GetFeedbackStream reads feedback from MongoDB by stream.
func (*MongoDB) GetItem ¶
GetItem returns a item from MongoDB.
func (*MongoDB) GetItemFeedback ¶
GetItemFeedback returns feedback of a item from MongoDB.
func (*MongoDB) GetItemStream ¶
GetItemStream read items from MongoDB by stream.
func (*MongoDB) GetItems ¶
GetItems returns items from MongoDB.
func (*MongoDB) GetUser ¶
GetUser returns a user from MongoDB.
func (*MongoDB) GetUserFeedback ¶
func (db *MongoDB) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error)
GetUserFeedback returns feedback of a user from MongoDB.
func (*MongoDB) GetUserItemFeedback ¶
func (db *MongoDB) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetUserItemFeedback returns a feedback return the user id and item id from MongoDB.
func (*MongoDB) GetUserStream ¶
GetUserStream reads users from MongoDB by stream.
func (*MongoDB) GetUsers ¶
GetUsers returns users from MongoDB.
func (*MongoDB) ModifyItem ¶
ModifyItem modify an item in MongoDB.
func (*MongoDB) ModifyUser ¶
ModifyUser modify a user in MongoDB.
type NoDatabase ¶
type NoDatabase struct{}
NoDatabase means that no database used.
func (NoDatabase) BatchGetItems ¶
func (NoDatabase) BatchGetItems(_ []string) ([]Item, error)
BatchGetItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) BatchInsertFeedback ¶
func (NoDatabase) BatchInsertFeedback(_ []Feedback, _, _, _ bool) error
BatchInsertFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) BatchInsertItems ¶
func (NoDatabase) BatchInsertItems(_ []Item) error
BatchInsertItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) BatchInsertUsers ¶
func (NoDatabase) BatchInsertUsers(_ []User) error
BatchInsertUsers method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Close ¶
func (NoDatabase) Close() error
Close method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) DeleteItem ¶
func (NoDatabase) DeleteItem(_ string) error
DeleteItem method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) DeleteUser ¶
func (NoDatabase) DeleteUser(_ string) error
DeleteUser method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) DeleteUserItemFeedback ¶
func (NoDatabase) DeleteUserItemFeedback(_, _ string, _ ...string) (int, error)
DeleteUserItemFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetFeedback ¶
func (NoDatabase) GetFeedback(_ string, _ int, _ *time.Time, _ ...string) (string, []Feedback, error)
GetFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetFeedbackStream ¶
GetFeedbackStream method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItem ¶
func (NoDatabase) GetItem(_ string) (Item, error)
GetItem method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItemFeedback ¶
func (NoDatabase) GetItemFeedback(_ string, _ ...string) ([]Feedback, error)
GetItemFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItemStream ¶
GetItemStream method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetItems ¶
GetItems method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUser ¶
func (NoDatabase) GetUser(_ string) (User, error)
GetUser method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUserFeedback ¶
GetUserFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUserItemFeedback ¶
func (NoDatabase) GetUserItemFeedback(_, _ string, _ ...string) ([]Feedback, error)
GetUserItemFeedback method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUserStream ¶
func (NoDatabase) GetUserStream(_ int) (chan []User, chan error)
GetUserStream method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) GetUsers ¶
GetUsers method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) Init ¶
func (NoDatabase) Init() error
Init method of NoDatabase returns ErrNoDatabase.
func (NoDatabase) ModifyItem ¶
func (d NoDatabase) ModifyItem(_ string, _ ItemPatch) error
func (NoDatabase) ModifyUser ¶
func (d NoDatabase) ModifyUser(_ string, _ UserPatch) error
func (NoDatabase) Optimize ¶
func (NoDatabase) Optimize() error
Optimize is used by ClickHouse only.
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
Redis use Redis as data storage, but used for test only.
func (*Redis) BatchInsertFeedback ¶
func (r *Redis) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error
BatchInsertFeedback insert a batch feedback into Redis. If insertUser set, new users will be insert to user table. If insertItem set, new items will be insert to item table.
func (*Redis) BatchInsertItems ¶
BatchInsertItems inserts a batch of items into Redis.
func (*Redis) BatchInsertUsers ¶
BatchInsertUsers inserts a batch pf user into Redis.
func (*Redis) DeleteItem ¶
DeleteItem deletes a item from Redis.
func (*Redis) DeleteUser ¶
DeleteUser deletes a user from Redis.
func (*Redis) DeleteUserItemFeedback ¶
DeleteUserItemFeedback deletes a feedback by user id and item id from Redis.
func (*Redis) ForFeedback ¶
func (*Redis) GetFeedback ¶
func (r *Redis) GetFeedback(_ string, _ int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error)
GetFeedback returns feedback from Redis.
func (*Redis) GetFeedbackStream ¶
func (r *Redis) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error)
GetFeedbackStream reads feedback by stream.
func (*Redis) GetItem ¶
GetItem get a item from Redis.
func (*Redis) GetItemFeedback ¶
GetItemFeedback returns feedback of an item from Redis.
func (*Redis) GetItemStream ¶
GetItemStream read items from Redis by stream.
func (*Redis) GetItems ¶
GetItems returns items from Redis.
func (*Redis) GetUser ¶
GetUser returns a user from Redis.
func (*Redis) GetUserFeedback ¶
func (r *Redis) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error)
GetUserFeedback returns feedback of a user from Redis.
func (*Redis) GetUserItemFeedback ¶
func (r *Redis) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetUserItemFeedback gets a feedback by user id and item id from Redis.
func (*Redis) GetUserStream ¶
GetUserStream read users from Redis by stream.
func (*Redis) GetUsers ¶
GetUsers returns users from Redis.
func (*Redis) ModifyItem ¶
ModifyItem modify an item in Redis.
func (*Redis) ModifyUser ¶
ModifyUser modify a user in Redis.
type SQLDatabase ¶
type SQLDatabase struct {
// contains filtered or unexported fields
}
SQLDatabase use MySQL as data storage.
func (*SQLDatabase) BatchGetItems ¶
func (d *SQLDatabase) BatchGetItems(itemIds []string) ([]Item, error)
func (*SQLDatabase) BatchInsertFeedback ¶
func (d *SQLDatabase) BatchInsertFeedback(feedback []Feedback, insertUser, insertItem, overwrite bool) error
BatchInsertFeedback insert a batch feedback into MySQL. If insertUser set, new users will be inserted to user table. If insertItem set, new items will be inserted to item table.
func (*SQLDatabase) BatchInsertItems ¶
func (d *SQLDatabase) BatchInsertItems(items []Item) error
BatchInsertItems inserts a batch of items into MySQL.
func (*SQLDatabase) BatchInsertUsers ¶
func (d *SQLDatabase) BatchInsertUsers(users []User) error
BatchInsertUsers inserts users into MySQL.
func (*SQLDatabase) DeleteItem ¶
func (d *SQLDatabase) DeleteItem(itemId string) error
DeleteItem deletes a item from MySQL.
func (*SQLDatabase) DeleteUser ¶
func (d *SQLDatabase) DeleteUser(userId string) error
DeleteUser deletes a user from MySQL.
func (*SQLDatabase) DeleteUserItemFeedback ¶
func (d *SQLDatabase) DeleteUserItemFeedback(userId, itemId string, feedbackTypes ...string) (int, error)
DeleteUserItemFeedback deletes a feedback by user id and item id from MySQL.
func (*SQLDatabase) GetFeedback ¶
func (d *SQLDatabase) GetFeedback(cursor string, n int, timeLimit *time.Time, feedbackTypes ...string) (string, []Feedback, error)
GetFeedback returns feedback from MySQL.
func (*SQLDatabase) GetFeedbackStream ¶
func (d *SQLDatabase) GetFeedbackStream(batchSize int, timeLimit *time.Time, feedbackTypes ...string) (chan []Feedback, chan error)
GetFeedbackStream reads feedback by stream.
func (*SQLDatabase) GetItem ¶
func (d *SQLDatabase) GetItem(itemId string) (Item, error)
GetItem get a item from MySQL.
func (*SQLDatabase) GetItemFeedback ¶
func (d *SQLDatabase) GetItemFeedback(itemId string, feedbackTypes ...string) ([]Feedback, error)
GetItemFeedback returns feedback of a item from MySQL.
func (*SQLDatabase) GetItemStream ¶
GetItemStream reads items by stream.
func (*SQLDatabase) GetItems ¶
GetItems returns items from MySQL.
func (*SQLDatabase) GetUser ¶
func (d *SQLDatabase) GetUser(userId string) (User, error)
GetUser returns a user from MySQL.
func (*SQLDatabase) GetUserFeedback ¶
func (d *SQLDatabase) GetUserFeedback(userId string, withFuture bool, feedbackTypes ...string) ([]Feedback, error)
GetUserFeedback returns feedback of a user from MySQL.
func (*SQLDatabase) GetUserItemFeedback ¶
func (d *SQLDatabase) GetUserItemFeedback(userId, itemId string, feedbackTypes ...string) ([]Feedback, error)
GetUserItemFeedback gets a feedback by user id and item id from MySQL.
func (*SQLDatabase) GetUserStream ¶
func (d *SQLDatabase) GetUserStream(batchSize int) (chan []User, chan error)
GetUserStream read users by stream.
func (*SQLDatabase) GetUsers ¶
GetUsers returns users from MySQL.
func (*SQLDatabase) ModifyItem ¶
func (d *SQLDatabase) ModifyItem(itemId string, patch ItemPatch) error
ModifyItem modify an item in MySQL.
func (*SQLDatabase) ModifyUser ¶
func (d *SQLDatabase) ModifyUser(userId string, patch UserPatch) error
ModifyUser modify a user in MySQL.
func (*SQLDatabase) Optimize ¶
func (d *SQLDatabase) Optimize() error
Optimize is used by ClickHouse only.