summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRandomChars <random@chars.jp>2021-09-09 18:28:52 +0900
committerRandomChars <random@chars.jp>2021-09-09 18:28:52 +0900
commit3525ce0fb2a4ededd4953082db8f82e957c76e2f (patch)
tree3c513fd9d6329db482fbf590b505ffe45668bd97
parent72e131058960483514c552faa66695841380548f (diff)
implement image group fetching in clientv1.2.2
-rw-r--r--client/image.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/client/image.go b/client/image.go
index 9a43dac..f925544 100644
--- a/client/image.go
+++ b/client/image.go
@@ -48,6 +48,44 @@ func (r *Remote) Image(flake string) (store.Image, error) {
return image, err
}
+// ImageGroup returns an entire group of store.Image.
+func (r *Remote) ImageGroup(flake string) ([]store.Image, error) {
+ if image, err := r.Image(flake); err != nil {
+ return nil, err
+ } else {
+ var group []store.Image
+
+ // Iterate forwards
+ if err = func(image store.Image) error {
+ group = []store.Image{image}
+ for image.Child != "" {
+ if image, err = r.Image(image.Child); err != nil {
+ return err
+ }
+ group = append(group, image)
+ }
+ return nil
+ }(image); err != nil {
+ return group, err
+ }
+
+ // Iterate backwards
+ if err = func(image store.Image) error {
+ for image.Parent != "" {
+ if image, err = r.Image(image.Parent); err != nil {
+ return err
+ }
+ group = append([]store.Image{image}, group...)
+ }
+ return nil
+ }(image); err != nil {
+ return group, err
+ }
+
+ return group, nil
+ }
+}
+
// ImageUpdate updates metadata of store.Image with given snowflake. To persist original value in a field set \000.
func (r *Remote) ImageUpdate(flake, source, parent, commentary, commentaryTranslation string) error {
payload := api.ImageUpdatePayload{