github.com/opsramp/moby@v1.13.1/client/task_inspect.go (about)

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