Files
moby/client/task_inspect.go
Sebastiaan van Stijn 58356450fa client: remove redundant closing and draining of response
For methods using the decodeWithRaw utility, we were handling closing
of the body twice. The ensureReaderClosed utility also drains the
response to let the transport reuse the connnection. Let's use that
utility in decodeWithRaw as well.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-24 19:30:22 +02:00

37 lines
863 B
Go

package client
import (
"context"
"encoding/json"
"github.com/moby/moby/api/types/swarm"
)
// TaskInspectOptions contains options for inspecting a task.
type TaskInspectOptions struct {
// Currently no options are defined.
}
// TaskInspectResult contains the result of a task inspection.
type TaskInspectResult struct {
Task swarm.Task
Raw json.RawMessage
}
// TaskInspect returns the task information and its raw representation.
func (cli *Client) TaskInspect(ctx context.Context, taskID string, options TaskInspectOptions) (TaskInspectResult, error) {
taskID, err := trimID("task", taskID)
if err != nil {
return TaskInspectResult{}, err
}
resp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil)
if err != nil {
return TaskInspectResult{}, err
}
var out TaskInspectResult
out.Raw, err = decodeWithRaw(resp, &out.Task)
return out, err
}