mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
Co-authored-by: Claude <noreply@anthropic.com> Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package client
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"net/url"
|
|
|
|
"github.com/moby/moby/api/types/swarm"
|
|
)
|
|
|
|
// ServiceInspectOptions holds parameters related to the service inspect operation.
|
|
type ServiceInspectOptions struct {
|
|
InsertDefaults bool
|
|
}
|
|
|
|
// ServiceInspectResult represents the result of a service inspect operation.
|
|
type ServiceInspectResult struct {
|
|
Service swarm.Service
|
|
Raw []byte
|
|
}
|
|
|
|
// ServiceInspect retrieves detailed information about a specific service by its ID.
|
|
func (cli *Client) ServiceInspect(ctx context.Context, serviceID string, options ServiceInspectOptions) (ServiceInspectResult, error) {
|
|
serviceID, err := trimID("service", serviceID)
|
|
if err != nil {
|
|
return ServiceInspectResult{}, err
|
|
}
|
|
|
|
query := url.Values{}
|
|
query.Set("insertDefaults", fmt.Sprintf("%v", options.InsertDefaults))
|
|
resp, err := cli.get(ctx, "/services/"+serviceID, query, nil)
|
|
defer ensureReaderClosed(resp)
|
|
if err != nil {
|
|
return ServiceInspectResult{}, err
|
|
}
|
|
|
|
var out ServiceInspectResult
|
|
out.Raw, err = decodeWithRaw(resp, &out.Service)
|
|
return out, err
|
|
}
|