Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Cleanup ¶
func Cleanup(tb testing.TB, nw TerminableNetwork)
Cleanup is a helper function that schedules the network to be removed when the test ends. This should be the first call after New in a test before any error check. If network is nil, it's a no-op.
func CleanupByID ¶
CleanupByID is a helper function that schedules the network to be removed, identified by its ID, when the test ends. This should be the first call after NewNetwork(...) in a test before any error check. If network is nil, it's a no-op. It uses a new docker client to terminate the network, which is automatically closed when the test ends.
Types ¶
type InspectOptions ¶
type InspectOptions func(opts *inspectOptions) error
InspectOptions is a function that modifies the inspect options.
func WithInspectOptions ¶
func WithInspectOptions(opts network.InspectOptions) InspectOptions
WithInspectOptions returns an InspectOptions that sets the inspect options.
func WithNoCache ¶
func WithNoCache() InspectOptions
WithNoCache returns an InspectOptions that disables caching the result of the inspection. If passed, the Docker daemon will be queried for the latest information, so it can be used for refreshing the cached result of a previous inspection.
type Network ¶
type Network struct {
// contains filtered or unexported fields
}
Network represents a Docker network.
func New ¶
New creates a new network.
Example ¶
package main
import (
"context"
"fmt"
"github.com/docker/go-sdk/network"
)
func main() {
nw, err := network.New(context.Background())
fmt.Println(err)
fmt.Println(nw.Name() != "")
err = nw.Terminate(context.Background())
fmt.Println(err)
}
Output: <nil> true <nil>
Example (WithClient) ¶
package main
import (
"context"
"fmt"
"github.com/docker/go-sdk/client"
"github.com/docker/go-sdk/network"
)
func main() {
dockerClient, err := client.New(context.Background())
fmt.Println(err)
nw, err := network.New(context.Background(), network.WithClient(dockerClient))
fmt.Println(err)
fmt.Println(nw.Name() != "")
err = nw.Terminate(context.Background())
fmt.Println(err)
}
Output: <nil> <nil> true <nil>
Example (WithOptions) ¶
package main
import (
"context"
"fmt"
"runtime"
"github.com/docker/go-sdk/network"
)
func main() {
name := "test-network"
driver := "bridge"
if runtime.GOOS == "windows" {
driver = "nat"
}
nw, err := network.New(
context.Background(),
network.WithName(name),
network.WithDriver(driver),
network.WithLabels(map[string]string{"test": "test"}),
network.WithAttachable(),
)
fmt.Println(err)
fmt.Println(nw.Name())
fmt.Println(nw.Driver() != "")
err = nw.Terminate(context.Background())
fmt.Println(err)
}
Output: <nil> test-network true <nil>
func (*Network) Inspect ¶
Inspect inspects the network, caching the results.
Example ¶
package main
import (
"context"
"fmt"
"github.com/docker/go-sdk/network"
)
func main() {
name := "test-network-inspect"
nw, err := network.New(context.Background(), network.WithName(name))
fmt.Println(err)
inspect, err := nw.Inspect(context.Background())
fmt.Println(err)
fmt.Println(inspect.Name)
err = nw.Terminate(context.Background())
fmt.Println(err)
}
Output: <nil> <nil> test-network-inspect <nil>
Example (WithOptions) ¶
package main
import (
"context"
"fmt"
apinetwork "github.com/docker/docker/api/types/network"
"github.com/docker/go-sdk/network"
)
func main() {
name := "test-network-inspect-options"
nw, err := network.New(context.Background(), network.WithName(name))
fmt.Println(err)
inspect, err := nw.Inspect(
context.Background(),
network.WithNoCache(),
network.WithInspectOptions(apinetwork.InspectOptions{
Verbose: true,
Scope: "local",
}),
)
fmt.Println(err)
fmt.Println(inspect.Name)
err = nw.Terminate(context.Background())
fmt.Println(err)
}
Output: <nil> <nil> test-network-inspect-options <nil>
func (*Network) Terminate ¶
Terminate is used to remove the network. It is usually triggered by as defer function.
Example ¶
package main
import (
"context"
"fmt"
"github.com/docker/go-sdk/network"
)
func main() {
nw, err := network.New(context.Background())
fmt.Println(err)
err = nw.Terminate(context.Background())
fmt.Println(err)
}
Output: <nil> <nil>
type Option ¶
type Option func(*options) error
Option is a function that modifies the options to create a network.
func WithLabels ¶
WithLabels sets the labels of the network.
type TerminableNetwork ¶
TerminableNetwork is a network that can be terminated.