Files
moby/client/checkpoint_list.go
Paweł Gronowski b48fcf6cdb client/checkpoint_list: Wrap result in a struct
The CheckpointList method previously returned a raw slice of
checkpoint.Summary, which made it difficult to extend the API response
with additional metadata or fields in the future without breaking
backward compatibility.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-09-26 17:03:07 +02:00

39 lines
982 B
Go

package client
import (
"context"
"encoding/json"
"net/url"
"github.com/moby/moby/api/types/checkpoint"
)
// CheckpointListOptions holds parameters to list checkpoints for a container.
type CheckpointListOptions struct {
CheckpointDir string
}
// CheckpointListResult holds the result from the CheckpointList method.
type CheckpointListResult struct {
Checkpoints []checkpoint.Summary
}
// CheckpointList returns the checkpoints of the given container in the docker host.
func (cli *Client) CheckpointList(ctx context.Context, container string, options CheckpointListOptions) (CheckpointListResult, error) {
var out CheckpointListResult
query := url.Values{}
if options.CheckpointDir != "" {
query.Set("dir", options.CheckpointDir)
}
resp, err := cli.get(ctx, "/containers/"+container+"/checkpoints", query, nil)
defer ensureReaderClosed(resp)
if err != nil {
return out, err
}
err = json.NewDecoder(resp.Body).Decode(&out.Checkpoints)
return out, err
}