cli/compose: use strings.Cut

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2022-12-27 17:44:59 +01:00
parent cb19bf9f7d
commit 3bed830a27
3 changed files with 15 additions and 16 deletions

View File

@ -427,11 +427,11 @@ func uint32Ptr(value uint32) *uint32 {
// convertExtraHosts converts <host>:<ip> mappings to SwarmKit notation:
// "IP-address hostname(s)". The original order of mappings is preserved.
func convertExtraHosts(extraHosts composetypes.HostsList) []string {
hosts := []string{}
hosts := make([]string, 0, len(extraHosts))
for _, hostIP := range extraHosts {
if v := strings.SplitN(hostIP, ":", 2); len(v) == 2 {
if hostName, ipAddr, ok := strings.Cut(hostIP, ":"); ok {
// Convert to SwarmKit notation: IP-address hostname(s)
hosts = append(hosts, fmt.Sprintf("%s %s", v[1], v[0]))
hosts = append(hosts, ipAddr+" "+hostName)
}
}
return hosts