2018-02-05 21:05:59 +00:00
|
|
|
package client // import "github.com/docker/docker/client"
|
2016-09-06 18:46:37 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
2018-04-19 22:30:59 +00:00
|
|
|
"context"
|
2016-09-06 18:46:37 +00:00
|
|
|
"encoding/json"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
|
|
)
|
|
|
|
|
2021-02-16 15:07:44 +00:00
|
|
|
// TaskInspectWithRaw returns the task information and its raw representation.
|
2016-09-06 18:46:37 +00:00
|
|
|
func (cli *Client) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) {
|
2018-01-30 12:35:22 +00:00
|
|
|
if taskID == "" {
|
|
|
|
return swarm.Task{}, nil, objectNotFoundError{object: "task", id: taskID}
|
|
|
|
}
|
2016-09-06 18:46:37 +00:00
|
|
|
serverResp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil)
|
2019-02-11 12:26:12 +00:00
|
|
|
defer ensureReaderClosed(serverResp)
|
2016-09-06 18:46:37 +00:00
|
|
|
if err != nil {
|
2017-09-08 16:04:34 +00:00
|
|
|
return swarm.Task{}, nil, wrapResponseError(err, serverResp, "task", taskID)
|
2016-09-06 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
body, err := ioutil.ReadAll(serverResp.body)
|
|
|
|
if err != nil {
|
|
|
|
return swarm.Task{}, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var response swarm.Task
|
|
|
|
rdr := bytes.NewReader(body)
|
|
|
|
err = json.NewDecoder(rdr).Decode(&response)
|
|
|
|
return response, body, err
|
|
|
|
}
|