1package client // import "github.com/docker/docker/client" 2 3import ( 4 "bytes" 5 "context" 6 "encoding/json" 7 "io/ioutil" 8 9 "github.com/docker/docker/api/types/swarm" 10) 11 12// TaskInspectWithRaw returns the task information and its raw representation.. 13func (cli *Client) TaskInspectWithRaw(ctx context.Context, taskID string) (swarm.Task, []byte, error) { 14 if taskID == "" { 15 return swarm.Task{}, nil, objectNotFoundError{object: "task", id: taskID} 16 } 17 serverResp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil) 18 defer ensureReaderClosed(serverResp) 19 if err != nil { 20 return swarm.Task{}, nil, wrapResponseError(err, serverResp, "task", taskID) 21 } 22 23 body, err := ioutil.ReadAll(serverResp.body) 24 if err != nil { 25 return swarm.Task{}, nil, err 26 } 27 28 var response swarm.Task 29 rdr := bytes.NewReader(body) 30 err = json.NewDecoder(rdr).Decode(&response) 31 return response, body, err 32} 33