-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add consistent snippets for network creation (#2703)
* docs: add consistent snippets for network creation * fix: lint
- Loading branch information
1 parent
e4ce806
commit 150a48c
Showing
3 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package network_test | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
|
||
dockernetwork "github.com/docker/docker/api/types/network" | ||
|
||
"github.com/testcontainers/testcontainers-go/network" | ||
) | ||
|
||
func ExampleNew() { | ||
// createNetwork { | ||
ctx := context.Background() | ||
|
||
net, err := network.New(ctx) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer func() { | ||
if err := net.Remove(ctx); err != nil { | ||
log.Fatalf("failed to remove network: %s", err) | ||
} | ||
}() | ||
// } | ||
|
||
fmt.Println(net.ID != "") | ||
fmt.Println(net.Driver) | ||
|
||
// Output: | ||
// true | ||
// bridge | ||
} | ||
|
||
func ExampleNew_withOptions() { | ||
// newNetworkWithOptions { | ||
ctx := context.Background() | ||
|
||
// dockernetwork is the alias used for github.com/docker/docker/api/types/network | ||
ipamConfig := dockernetwork.IPAM{ | ||
Driver: "default", | ||
Config: []dockernetwork.IPAMConfig{ | ||
{ | ||
Subnet: "10.1.1.0/24", | ||
Gateway: "10.1.1.254", | ||
}, | ||
}, | ||
Options: map[string]string{ | ||
"driver": "host-local", | ||
}, | ||
} | ||
net, err := network.New(ctx, | ||
network.WithIPAM(&ipamConfig), | ||
network.WithAttachable(), | ||
network.WithDriver("bridge"), | ||
) | ||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
defer func() { | ||
if err := net.Remove(ctx); err != nil { | ||
log.Fatalf("failed to remove network: %s", err) | ||
} | ||
}() | ||
// } | ||
|
||
fmt.Println(net.ID != "") | ||
fmt.Println(net.Driver) | ||
|
||
// Output: | ||
// true | ||
// bridge | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters