-
Notifications
You must be signed in to change notification settings - Fork 0
/
storage.go
33 lines (26 loc) · 833 Bytes
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package interfaces
import (
"image"
"github.com/co0p/tics/domain"
)
// StorageHandler allows us to swap in different implementations of the actual storage method
type StorageHandler interface {
Add(hash string, image image.Image)
Get(hash string) (image.Image, bool)
}
type ThumbnailStorageRepo struct {
StorageHandler StorageHandler
}
func NewThumbnailStorageRepo(handler StorageHandler) *ThumbnailStorageRepo {
return &ThumbnailStorageRepo{StorageHandler: handler}
}
func (tr *ThumbnailStorageRepo) Add(thumbnail domain.Thumbnail) {
tr.StorageHandler.Add(thumbnail.GetHash(), thumbnail.GetImage())
}
func (tr *ThumbnailStorageRepo) Get(hash string) (domain.Thumbnail, bool) {
img, found := tr.StorageHandler.Get(hash)
if !found {
return domain.Thumbnail{}, false
}
return domain.NewThumbnail(hash, img), true
}