github.com/hms58/moby@v1.13.1/client/service_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 "golang.org/x/net/context" 11 ) 12 13 // ServiceInspectWithRaw returns the service information and the raw data. 14 func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string) (swarm.Service, []byte, error) { 15 serverResp, err := cli.get(ctx, "/services/"+serviceID, nil, nil) 16 if err != nil { 17 if serverResp.statusCode == http.StatusNotFound { 18 return swarm.Service{}, nil, serviceNotFoundError{serviceID} 19 } 20 return swarm.Service{}, nil, err 21 } 22 defer ensureReaderClosed(serverResp) 23 24 body, err := ioutil.ReadAll(serverResp.body) 25 if err != nil { 26 return swarm.Service{}, nil, err 27 } 28 29 var response swarm.Service 30 rdr := bytes.NewReader(body) 31 err = json.NewDecoder(rdr).Decode(&response) 32 return response, body, err 33 }