mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
39 lines
919 B
Go
39 lines
919 B
Go
package client
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/swarm"
|
|
)
|
|
|
|
// ServiceInspectWithRaw returns the service information and the raw data.
|
|
func (cli *Client) ServiceInspectWithRaw(ctx context.Context, serviceID string, opts ServiceInspectOptions) (swarm.Service, []byte, error) {
|
|
serviceID, err := trimID("service", serviceID)
|
|
if err != nil {
|
|
return swarm.Service{}, nil, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("insertDefaults", fmt.Sprintf("%v", opts.InsertDefaults))
|
|
resp, err := cli.get(ctx, "/services/"+serviceID, query, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return swarm.Service{}, nil, err
|
|
}
|
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
if err != nil {
|
|
return swarm.Service{}, nil, err
|
|
}
|
|
|
|
var response swarm.Service
|
|
rdr := bytes.NewReader(body)
|
|
err = json.NewDecoder(rdr).Decode(&response)
|
|
return response, body, err
|
|
}
|