client: un-export NewVersionError, rename to requiresVersion

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-10-29 12:43:08 +01:00
parent 7041c02abd
commit 2d6bf9332b
12 changed files with 20 additions and 20 deletions

View File

@@ -53,12 +53,12 @@ func (e objectNotFoundError) Error() string {
return fmt.Sprintf("Error: No such %s: %s", e.object, e.id) return fmt.Sprintf("Error: No such %s: %s", e.object, e.id)
} }
// NewVersionError returns an error if the APIVersion required is less than the // requiresVersion returns an error if the APIVersion required is less than the
// current supported version. // current supported version.
// //
// It performs API-version negotiation if the Client is configured with this // It performs API-version negotiation if the Client is configured with this
// option, otherwise it assumes the latest API version is used. // option, otherwise it assumes the latest API version is used.
func (cli *Client) NewVersionError(ctx context.Context, APIrequired, feature string) error { func (cli *Client) requiresVersion(ctx context.Context, apiRequired, feature string) error {
// Make sure we negotiated (if the client is configured to do so), // Make sure we negotiated (if the client is configured to do so),
// as code below contains API-version specific handling of options. // as code below contains API-version specific handling of options.
// //
@@ -67,8 +67,8 @@ func (cli *Client) NewVersionError(ctx context.Context, APIrequired, feature str
if err := cli.checkVersion(ctx); err != nil { if err := cli.checkVersion(ctx); err != nil {
return err return err
} }
if cli.version != "" && versions.LessThan(cli.version, APIrequired) { if cli.version != "" && versions.LessThan(cli.version, apiRequired) {
return fmt.Errorf("%q requires API version %s, but the Docker daemon API version is %s", feature, APIrequired, cli.version) return fmt.Errorf("%q requires API version %s, but the Docker daemon API version is %s", feature, apiRequired, cli.version)
} }
return nil return nil
} }

View File

@@ -32,7 +32,7 @@ func (cli *Client) ImageHistory(ctx context.Context, imageID string, historyOpts
} }
if opts.apiOptions.Platform != nil { if opts.apiOptions.Platform != nil {
if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "platform"); err != nil {
return ImageHistoryResult{}, err return ImageHistoryResult{}, err
} }

View File

@@ -24,14 +24,14 @@ func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts
query := url.Values{} query := url.Values{}
if opts.apiOptions.Manifests { if opts.apiOptions.Manifests {
if err := cli.NewVersionError(ctx, "1.48", "manifests"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "manifests"); err != nil {
return ImageInspectResult{}, err return ImageInspectResult{}, err
} }
query.Set("manifests", "1") query.Set("manifests", "1")
} }
if opts.apiOptions.Platform != nil { if opts.apiOptions.Platform != nil {
if err := cli.NewVersionError(ctx, "1.49", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.49", "platform"); err != nil {
return ImageInspectResult{}, err return ImageInspectResult{}, err
} }
platform, err := encodePlatform(opts.apiOptions.Platform) platform, err := encodePlatform(opts.apiOptions.Platform)

View File

@@ -28,7 +28,7 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
query.Set("quiet", "1") query.Set("quiet", "1")
} }
if len(opts.apiOptions.Platforms) > 0 { if len(opts.apiOptions.Platforms) > 0 {
if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "platform"); err != nil {
return ImageLoadResult{}, err return ImageLoadResult{}, err
} }

View File

@@ -50,7 +50,7 @@ func (cli *Client) ImagePush(ctx context.Context, image string, options ImagePus
} }
if options.Platform != nil { if options.Platform != nil {
if err := cli.NewVersionError(ctx, "1.46", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.46", "platform"); err != nil {
return nil, err return nil, err
} }

View File

@@ -24,7 +24,7 @@ func (cli *Client) ImageSave(ctx context.Context, imageIDs []string, saveOpts ..
} }
if len(opts.apiOptions.Platforms) > 0 { if len(opts.apiOptions.Platforms) > 0 {
if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "platform"); err != nil {
return ImageSaveResult{}, err return ImageSaveResult{}, err
} }
p, err := encodePlatforms(opts.apiOptions.Platforms...) p, err := encodePlatforms(opts.apiOptions.Platforms...)

View File

@@ -53,12 +53,12 @@ func (e objectNotFoundError) Error() string {
return fmt.Sprintf("Error: No such %s: %s", e.object, e.id) return fmt.Sprintf("Error: No such %s: %s", e.object, e.id)
} }
// NewVersionError returns an error if the APIVersion required is less than the // requiresVersion returns an error if the APIVersion required is less than the
// current supported version. // current supported version.
// //
// It performs API-version negotiation if the Client is configured with this // It performs API-version negotiation if the Client is configured with this
// option, otherwise it assumes the latest API version is used. // option, otherwise it assumes the latest API version is used.
func (cli *Client) NewVersionError(ctx context.Context, APIrequired, feature string) error { func (cli *Client) requiresVersion(ctx context.Context, apiRequired, feature string) error {
// Make sure we negotiated (if the client is configured to do so), // Make sure we negotiated (if the client is configured to do so),
// as code below contains API-version specific handling of options. // as code below contains API-version specific handling of options.
// //
@@ -67,8 +67,8 @@ func (cli *Client) NewVersionError(ctx context.Context, APIrequired, feature str
if err := cli.checkVersion(ctx); err != nil { if err := cli.checkVersion(ctx); err != nil {
return err return err
} }
if cli.version != "" && versions.LessThan(cli.version, APIrequired) { if cli.version != "" && versions.LessThan(cli.version, apiRequired) {
return fmt.Errorf("%q requires API version %s, but the Docker daemon API version is %s", feature, APIrequired, cli.version) return fmt.Errorf("%q requires API version %s, but the Docker daemon API version is %s", feature, apiRequired, cli.version)
} }
return nil return nil
} }

View File

@@ -32,7 +32,7 @@ func (cli *Client) ImageHistory(ctx context.Context, imageID string, historyOpts
} }
if opts.apiOptions.Platform != nil { if opts.apiOptions.Platform != nil {
if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "platform"); err != nil {
return ImageHistoryResult{}, err return ImageHistoryResult{}, err
} }

View File

@@ -24,14 +24,14 @@ func (cli *Client) ImageInspect(ctx context.Context, imageID string, inspectOpts
query := url.Values{} query := url.Values{}
if opts.apiOptions.Manifests { if opts.apiOptions.Manifests {
if err := cli.NewVersionError(ctx, "1.48", "manifests"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "manifests"); err != nil {
return ImageInspectResult{}, err return ImageInspectResult{}, err
} }
query.Set("manifests", "1") query.Set("manifests", "1")
} }
if opts.apiOptions.Platform != nil { if opts.apiOptions.Platform != nil {
if err := cli.NewVersionError(ctx, "1.49", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.49", "platform"); err != nil {
return ImageInspectResult{}, err return ImageInspectResult{}, err
} }
platform, err := encodePlatform(opts.apiOptions.Platform) platform, err := encodePlatform(opts.apiOptions.Platform)

View File

@@ -28,7 +28,7 @@ func (cli *Client) ImageLoad(ctx context.Context, input io.Reader, loadOpts ...I
query.Set("quiet", "1") query.Set("quiet", "1")
} }
if len(opts.apiOptions.Platforms) > 0 { if len(opts.apiOptions.Platforms) > 0 {
if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "platform"); err != nil {
return ImageLoadResult{}, err return ImageLoadResult{}, err
} }

View File

@@ -50,7 +50,7 @@ func (cli *Client) ImagePush(ctx context.Context, image string, options ImagePus
} }
if options.Platform != nil { if options.Platform != nil {
if err := cli.NewVersionError(ctx, "1.46", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.46", "platform"); err != nil {
return nil, err return nil, err
} }

View File

@@ -24,7 +24,7 @@ func (cli *Client) ImageSave(ctx context.Context, imageIDs []string, saveOpts ..
} }
if len(opts.apiOptions.Platforms) > 0 { if len(opts.apiOptions.Platforms) > 0 {
if err := cli.NewVersionError(ctx, "1.48", "platform"); err != nil { if err := cli.requiresVersion(ctx, "1.48", "platform"); err != nil {
return ImageSaveResult{}, err return ImageSaveResult{}, err
} }
p, err := encodePlatforms(opts.apiOptions.Platforms...) p, err := encodePlatforms(opts.apiOptions.Platforms...)