Documentation ¶
Index ¶
- Constants
- Variables
- func GenerateID() string
- type BoltStorage
- func (b *BoltStorage) Get(word string) (DictionaryItem, error)
- func (b *BoltStorage) GetQuiz(id string) (Quiz, error)
- func (b *BoltStorage) GetUser(user UserID) (User, error)
- func (b *BoltStorage) GetUserDictionary(user UserID) (map[UserDictionaryItem]DictionaryItem, error)
- func (b *BoltStorage) GetUserItem(user UserID, word string) (UserDictionaryItem, error)
- func (b *BoltStorage) Save(item DictionaryItem) error
- func (b *BoltStorage) SaveQuiz(quiz Quiz) error
- func (b *BoltStorage) SaveUser(user User) error
- func (b *BoltStorage) SaveUserItem(item UserDictionaryItem) error
- type DictionaryItem
- type InMemoryStorage
- func (d *InMemoryStorage) Get(word string) (DictionaryItem, error)
- func (d *InMemoryStorage) GetQuiz(id string) (Quiz, error)
- func (d *InMemoryStorage) GetUser(id UserID) (User, error)
- func (d *InMemoryStorage) GetUserDictionary(user UserID) (map[UserDictionaryItem]DictionaryItem, error)
- func (d *InMemoryStorage) GetUserItem(user UserID, word string) (UserDictionaryItem, error)
- func (d *InMemoryStorage) Save(item DictionaryItem) error
- func (d *InMemoryStorage) SaveQuiz(q Quiz) error
- func (d *InMemoryStorage) SaveUser(item User) error
- func (d *InMemoryStorage) SaveUserItem(item UserDictionaryItem) error
- type Quiz
- type QuizItem
- type QuizResult
- type RedisStorage
- func (s *RedisStorage) Get(word string) (DictionaryItem, error)
- func (s *RedisStorage) GetQuiz(id string) (Quiz, error)
- func (s *RedisStorage) GetUser(id UserID) (User, error)
- func (s *RedisStorage) GetUserDictionary(user UserID) (map[UserDictionaryItem]DictionaryItem, error)
- func (s *RedisStorage) GetUserItem(user UserID, word string) (UserDictionaryItem, error)
- func (s *RedisStorage) Save(item DictionaryItem) error
- func (s *RedisStorage) SaveQuiz(q Quiz) error
- func (s *RedisStorage) SaveUser(user User) error
- func (s *RedisStorage) SaveUserItem(item UserDictionaryItem) error
- type Storage
- type User
- type UserConfig
- type UserDictionaryItem
- type UserID
Constants ¶
const ( QuizTypeTranslations = "translations" QuizTypeReverseTranslations = "rTranslations" QuizTypeMeanings = "meanings" QuizTypeDefault = QuizTypeTranslations )
types of quizzes
Variables ¶
var ErrNotFound error = errors.New("not found")
ErrNotFound is returned when object not found
Functions ¶
Types ¶
type BoltStorage ¶
type BoltStorage struct {
// contains filtered or unexported fields
}
BoltStorage is a storage implementation using BoltDB
func NewBoltStorage ¶
func NewBoltStorage(db *bolt.DB) (*BoltStorage, error)
NewBoltStorage creates BoltStorage instance and initialize buckets
func (*BoltStorage) Get ¶
func (b *BoltStorage) Get(word string) (DictionaryItem, error)
Get dictionary item from database
func (*BoltStorage) GetQuiz ¶
func (b *BoltStorage) GetQuiz(id string) (Quiz, error)
GetQuiz returns quiz by ID`
func (*BoltStorage) GetUser ¶
func (b *BoltStorage) GetUser(user UserID) (User, error)
GetUser returns user by id
func (*BoltStorage) GetUserDictionary ¶
func (b *BoltStorage) GetUserDictionary(user UserID) (map[UserDictionaryItem]DictionaryItem, error)
GetUserDictionary returns dictionary items for user
func (*BoltStorage) GetUserItem ¶
func (b *BoltStorage) GetUserItem(user UserID, word string) (UserDictionaryItem, error)
GetUserItem returns user dictionary item
func (*BoltStorage) Save ¶
func (b *BoltStorage) Save(item DictionaryItem) error
Save dictionary item to database
func (*BoltStorage) SaveQuiz ¶
func (b *BoltStorage) SaveQuiz(quiz Quiz) error
SaveQuiz saves quiz to database
func (*BoltStorage) SaveUser ¶
func (b *BoltStorage) SaveUser(user User) error
SaveUser saves user to database
func (*BoltStorage) SaveUserItem ¶
func (b *BoltStorage) SaveUserItem(item UserDictionaryItem) error
SaveUserItem saves user dictionary item to database
type DictionaryItem ¶
type DictionaryItem struct { Word string Phonetics struct { Text string Audio string } Meanings []meaning Translations []translation }
DictionaryItem hold data for a single dictionary item
func NewDictionaryItem ¶
func NewDictionaryItem( word string, dictionaryResponse []dictionaryapi.WordResponse, translations map[string]yandexdictionary.TranslationResponse, ) DictionaryItem
NewDictionaryItem creates new dictionary item from dictionary & translations responses
type InMemoryStorage ¶
type InMemoryStorage struct {
// contains filtered or unexported fields
}
InMemoryStorage is a storage implementation using in-memory maps
func NewInMemoryStorage ¶
func NewInMemoryStorage() *InMemoryStorage
NewInMemoryStorage creates new empty in-memory storage
func (*InMemoryStorage) Get ¶
func (d *InMemoryStorage) Get(word string) (DictionaryItem, error)
Get returns dictionary item by word
func (*InMemoryStorage) GetQuiz ¶
func (d *InMemoryStorage) GetQuiz(id string) (Quiz, error)
GetQuiz returns quiz by ID
func (*InMemoryStorage) GetUser ¶
func (d *InMemoryStorage) GetUser(id UserID) (User, error)
GetUser returns user by ID
func (*InMemoryStorage) GetUserDictionary ¶
func (d *InMemoryStorage) GetUserDictionary(user UserID) (map[UserDictionaryItem]DictionaryItem, error)
GetUserDictionary returns map of user dictionary items
func (*InMemoryStorage) GetUserItem ¶
func (d *InMemoryStorage) GetUserItem(user UserID, word string) (UserDictionaryItem, error)
GetUserItem returns item from user dictionary
func (*InMemoryStorage) Save ¶
func (d *InMemoryStorage) Save(item DictionaryItem) error
Save saves dictionary item
func (*InMemoryStorage) SaveQuiz ¶
func (d *InMemoryStorage) SaveQuiz(q Quiz) error
SaveQuiz saves quiz
func (*InMemoryStorage) SaveUser ¶
func (d *InMemoryStorage) SaveUser(item User) error
SaveUser saves user
func (*InMemoryStorage) SaveUserItem ¶
func (d *InMemoryStorage) SaveUserItem(item UserDictionaryItem) error
SaveUserItem saves UserDictionaryItem
type Quiz ¶
type Quiz struct { ID string User UserID Word string DisplayWord string Language string Type string Choices []QuizItem Created time.Time Result *QuizResult }
Quiz holds data for a single quiz`
type QuizResult ¶
QuizResult holds data for a quiz result
type RedisStorage ¶
type RedisStorage struct {
// contains filtered or unexported fields
}
RedisStorage is a storage implementation using redis
func NewRedisStorage ¶
func NewRedisStorage(url string) (*RedisStorage, error)
NewRedisStorage creates RedisStorage with given url
func (*RedisStorage) Get ¶
func (s *RedisStorage) Get(word string) (DictionaryItem, error)
Get word from redis
func (*RedisStorage) GetQuiz ¶
func (s *RedisStorage) GetQuiz(id string) (Quiz, error)
GetQuiz from redis
func (*RedisStorage) GetUser ¶
func (s *RedisStorage) GetUser(id UserID) (User, error)
GetUser from redis
func (*RedisStorage) GetUserDictionary ¶
func (s *RedisStorage) GetUserDictionary(user UserID) (map[UserDictionaryItem]DictionaryItem, error)
GetUserDictionary from redis
func (*RedisStorage) GetUserItem ¶
func (s *RedisStorage) GetUserItem(user UserID, word string) (UserDictionaryItem, error)
GetUserItem returns user item from redis
func (*RedisStorage) Save ¶
func (s *RedisStorage) Save(item DictionaryItem) error
Save word to redis
func (*RedisStorage) SaveUserItem ¶
func (s *RedisStorage) SaveUserItem(item UserDictionaryItem) error
SaveUserItem to redis
type Storage ¶
type Storage interface { // Get dictionary item by word Get(string) (DictionaryItem, error) // Save dictionary item to DB Save(DictionaryItem) error // GetUser returns user by ID GetUser(UserID) (User, error) // SaveUser saves user to DB SaveUser(User) error // GetUserDictionary returns item from user dictionary GetUserItem(UserID, string) (UserDictionaryItem, error) // SaveUserItem saves UserDictionaryItem SaveUserItem(UserDictionaryItem) error // GetUserDictionary returns map of user dictionary items GetUserDictionary(UserID) (map[UserDictionaryItem]DictionaryItem, error) // SaveQuiz saves quiz to DB SaveQuiz(Quiz) error // GetQuiz returns quiz by ID GetQuiz(string) (Quiz, error) }
Storage defines method provided by database interfaces
type User ¶
type User struct { ID UserID IsAdmin bool Username string Language string Config UserConfig }
User holds user data
type UserDictionaryItem ¶
UserDictionaryItem hold data for a single user dictionary item