Files
moby/client/network_inspect.go
Sebastiaan van Stijn 58356450fa client: remove redundant closing and draining of response
For methods using the decodeWithRaw utility, we were handling closing
of the body twice. The ensureReaderClosed utility also drains the
response to let the transport reuse the connnection. Let's use that
utility in decodeWithRaw as well.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-24 19:30:22 +02:00

40 lines
969 B
Go

package client
import (
"context"
"encoding/json"
"net/url"
"github.com/moby/moby/api/types/network"
)
// NetworkInspectResult contains the result of a network inspection.
type NetworkInspectResult struct {
Network network.Inspect
Raw json.RawMessage
}
// NetworkInspect returns the information for a specific network configured in the docker host.
func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options NetworkInspectOptions) (NetworkInspectResult, error) {
networkID, err := trimID("network", networkID)
if err != nil {
return NetworkInspectResult{}, err
}
query := url.Values{}
if options.Verbose {
query.Set("verbose", "true")
}
if options.Scope != "" {
query.Set("scope", options.Scope)
}
resp, err := cli.get(ctx, "/networks/"+networkID, query, nil)
if err != nil {
return NetworkInspectResult{}, err
}
var out NetworkInspectResult
out.Raw, err = decodeWithRaw(resp, &out.Network)
return out, err
}