-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage_handler.go
50 lines (43 loc) · 1.33 KB
/
image_handler.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
package goba
// An ImageHandler combines a Database with a Store to ensure
// that any images created by that Database are submitted to
// the store and that an Image can be loaded into the Database
// by name.
type ImageHandler struct {
DB Database
Store Store
}
// Type returns the type of h's Database.
func (h ImageHandler) Type() DatabaseType {
return h.DB.Type()
}
// CreateImage creates a new Image of h's Database,
// submits it to h's Store and returns it.
func (h ImageHandler) CreateImage() (*Image, error) {
image, err := h.DB.CreateImage()
if err != nil {
return nil, err
}
return image, h.Store.SaveImage(*image)
}
// ApplyImage retrieves the Image with the given name
// from h's Store and applies it to h's Database.
func (h ImageHandler) ApplyImage(name string) error {
image, err := h.Store.FindImage(name)
if err != nil {
return err
}
return h.DB.ApplyImage(*image)
}
// FindImage retrieves the Image with given name from h's Store.
func (h ImageHandler) FindImage(name string) (*Image, error) {
return h.Store.FindImage(name)
}
// AllImages retrieves all images from h's Store.
func (h ImageHandler) AllImages() ([]Image, error) {
return h.Store.AllImages()
}
// DeleteImage deletes the Image with the given name from h's Store.
func (h ImageHandler) DeleteImage(name string) error {
return h.Store.DeleteImage(name)
}