Files
moby/client/network_create.go
Sebastiaan van Stijn 7652f38c28 client: remove API-version compatibility for API < v1.44
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-08 23:43:59 +02:00

38 lines
993 B
Go

package client
import (
"context"
"encoding/json"
"github.com/moby/moby/api/types/network"
)
// NetworkCreate creates a new network in the docker host.
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
req := network.CreateRequest{
Name: name,
Driver: options.Driver,
Scope: options.Scope,
EnableIPv4: options.EnableIPv4,
EnableIPv6: options.EnableIPv6,
IPAM: options.IPAM,
Internal: options.Internal,
Attachable: options.Attachable,
Ingress: options.Ingress,
ConfigOnly: options.ConfigOnly,
ConfigFrom: options.ConfigFrom,
Options: options.Options,
Labels: options.Labels,
}
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
defer ensureReaderClosed(resp)
if err != nil {
return network.CreateResponse{}, err
}
var response network.CreateResponse
err = json.NewDecoder(resp.Body).Decode(&response)
return response, err
}