mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: use slices.Clone, maps.Collect in some places
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -4,10 +4,12 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net"
|
||||
"net/netip"
|
||||
"os"
|
||||
"runtime"
|
||||
"slices"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -115,16 +117,10 @@ func buildSandboxOptions(cfg *config.Config, ctr *container.Container) ([]libnet
|
||||
// slice (PortMap is a map[Port][]PortBinding).
|
||||
bindings := make(containertypes.PortMap)
|
||||
for p, b := range ctr.HostConfig.PortBindings {
|
||||
copied := make([]containertypes.PortBinding, len(b))
|
||||
copy(copied, b)
|
||||
bindings[p] = copied
|
||||
bindings[p] = slices.Clone(b)
|
||||
}
|
||||
|
||||
// TODO(thaJeztah): Move this code to a method on nat.PortSet.
|
||||
ports := make([]containertypes.PortRangeProto, 0, len(ctr.Config.ExposedPorts))
|
||||
for p := range ctr.Config.ExposedPorts {
|
||||
ports = append(ports, p)
|
||||
}
|
||||
ports := slices.Collect(maps.Keys(ctr.Config.ExposedPorts))
|
||||
nat.SortPortMap(ports, bindings)
|
||||
|
||||
var (
|
||||
|
||||
@@ -4,8 +4,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"maps"
|
||||
"net"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -954,16 +956,10 @@ func buildPortsRelatedCreateEndpointOptions(c *container.Container, n *libnetwor
|
||||
// slice (PortMap is a map[Port][]PortBinding).
|
||||
bindings := make(containertypes.PortMap)
|
||||
for p, b := range c.HostConfig.PortBindings {
|
||||
copied := make([]containertypes.PortBinding, len(b))
|
||||
copy(copied, b)
|
||||
bindings[p] = copied
|
||||
bindings[p] = slices.Clone(b)
|
||||
}
|
||||
|
||||
// TODO(thaJeztah): Move this code to a method on nat.PortSet.
|
||||
ports := make([]containertypes.PortRangeProto, 0, len(c.Config.ExposedPorts))
|
||||
for p := range c.Config.ExposedPorts {
|
||||
ports = append(ports, p)
|
||||
}
|
||||
ports := slices.Collect(maps.Keys(bindings))
|
||||
nat.SortPortMap(ports, bindings)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user