forked from ungerik/go-start
/
backend.go
64 lines (46 loc) · 1.78 KB
/
backend.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package media
import (
"io"
"github.com/ungerik/go-start/model"
)
type Backend interface {
// General file methods:
FileWriter(filename, contentType string) (writer io.WriteCloser, id string, err error)
// Returns ErrNotFound if no file with id is found.
FileReader(id string) (reader io.ReadCloser, filename, contentType string, err error)
// Returns ErrNotFound if no file with id is found.
DeleteFile(id string) error
// Blob methods:
LoadBlob(id string) (*Blob, error)
SaveBlob(blob *Blob) error
// DeleteBlob does not delete the file associated with it, also use DeleteFile().
DeleteBlob(blob *Blob) error
// BlobIterator returns an iterator that iterates
// all blobs as Blob structs.
BlobIterator() model.Iterator
// CountBlobRefs counts all BlobRef occurrences with blobID
// in all known databases.
CountBlobRefs(blobID string) (count int, err error)
// RemoveAllBlobRefs removes all BlobRef occurrences with blobID
// in all known databases.
RemoveAllBlobRefs(blobID string) (count int, err error)
// Image methods:
// Returns ErrNotFound if no image with id is found.
LoadImage(id string) (*Image, error)
// SaveImage saves image and updates its ID if it is empty.
SaveImage(image *Image) error
DeleteImage(image *Image) error
// ImageIterator returns an iterator that iterates
// all images as Image structs.
ImageIterator() model.Iterator
// CountImageRefs counts all ImageRef occurrences with imageID
// in all known databases.
CountImageRefs(imageID string) (count int, err error)
// RemoveAllImageRefs removes all ImageRef occurrences with imageID
// in all known databases.
RemoveAllImageRefs(imageID string) (count int, err error)
}
type ErrNotFound string
func (self ErrNotFound) Error() string {
return "Media not found: \"" + string(self) + "\""
}