2019-04-15 05:22:00 +05:30
|
|
|
package queue
|
|
|
|
|
|
|
|
import "github.com/elyby/chrly/api/mojang"
|
|
|
|
|
2019-04-21 00:52:02 +05:30
|
|
|
type UuidsStorage interface {
|
|
|
|
GetUuid(username string) (string, error)
|
|
|
|
StoreUuid(username string, uuid string)
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:36:29 +05:30
|
|
|
// nil value can be passed to the storage to indicate that there is no textures
|
|
|
|
// for uuid and we know about it. Return err only in case, when storage completely
|
|
|
|
// unable to load any information about textures
|
2019-04-21 00:52:02 +05:30
|
|
|
type TexturesStorage interface {
|
|
|
|
GetTextures(uuid string) (*mojang.SignedTexturesResponse, error)
|
2019-05-06 01:36:29 +05:30
|
|
|
StoreTextures(uuid string, textures *mojang.SignedTexturesResponse)
|
2019-04-15 05:22:00 +05:30
|
|
|
}
|
|
|
|
|
2019-04-21 00:52:02 +05:30
|
|
|
type Storage interface {
|
|
|
|
UuidsStorage
|
|
|
|
TexturesStorage
|
2019-04-15 05:22:00 +05:30
|
|
|
}
|
|
|
|
|
2019-04-27 04:16:15 +05:30
|
|
|
// SplittedStorage allows you to use separate storage engines to satisfy
|
|
|
|
// the Storage interface
|
|
|
|
type SplittedStorage struct {
|
|
|
|
UuidsStorage
|
|
|
|
TexturesStorage
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SplittedStorage) GetUuid(username string) (string, error) {
|
|
|
|
return s.UuidsStorage.GetUuid(username)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SplittedStorage) StoreUuid(username string, uuid string) {
|
|
|
|
s.UuidsStorage.StoreUuid(username, uuid)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SplittedStorage) GetTextures(uuid string) (*mojang.SignedTexturesResponse, error) {
|
|
|
|
return s.TexturesStorage.GetTextures(uuid)
|
|
|
|
}
|
|
|
|
|
2019-05-06 01:36:29 +05:30
|
|
|
func (s *SplittedStorage) StoreTextures(uuid string, textures *mojang.SignedTexturesResponse) {
|
|
|
|
s.TexturesStorage.StoreTextures(uuid, textures)
|
2019-04-27 04:16:15 +05:30
|
|
|
}
|
|
|
|
|
2019-04-21 00:52:02 +05:30
|
|
|
// This error can be used to indicate, that requested
|
|
|
|
// value doesn't exists in the storage
|
|
|
|
type ValueNotFound struct {
|
2019-04-15 05:22:00 +05:30
|
|
|
}
|
|
|
|
|
2019-04-21 00:52:02 +05:30
|
|
|
func (*ValueNotFound) Error() string {
|
2019-04-21 22:58:58 +05:30
|
|
|
return "value not found in the storage"
|
2019-04-15 05:22:00 +05:30
|
|
|
}
|