-
Notifications
You must be signed in to change notification settings - Fork 18.9k
Expand file tree
/
Copy pathimage_save_opts.go
More file actions
41 lines (33 loc) · 1.15 KB
/
image_save_opts.go
File metadata and controls
41 lines (33 loc) · 1.15 KB
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
package client
import (
"fmt"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
type ImageSaveOption interface {
Apply(*imageSaveOpts) error
}
type imageSaveOptionFunc func(opt *imageSaveOpts) error
func (f imageSaveOptionFunc) Apply(o *imageSaveOpts) error {
return f(o)
}
// ImageSaveWithPlatforms sets the platforms to be saved from the image. It
// produces an error if platforms are already set. This option only has an
// effect if the input image is a multi-platform image.
func ImageSaveWithPlatforms(platforms ...ocispec.Platform) ImageSaveOption {
// TODO(thaJeztah): verify the GoDoc; do we produce an error for a single-platform image without the given platform?
return imageSaveOptionFunc(func(opt *imageSaveOpts) error {
if opt.apiOptions.Platforms != nil {
return fmt.Errorf("platforms already set to %v", opt.apiOptions.Platforms)
}
opt.apiOptions.Platforms = platforms
return nil
})
}
type imageSaveOpts struct {
apiOptions imageSaveOptions
}
type imageSaveOptions struct {
// Platforms selects the platforms to save if the image is a
// multi-platform image and has multiple variants.
Platforms []ocispec.Platform
}