mirror of
https://github.com/moby/moby.git
synced 2026-01-11 02:31:44 +00:00
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>
40 lines
969 B
Go
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
|
|
}
|