github.com/heimweh/terraform@v0.7.4/communicator/shared/shared.go (about) 1 package shared 2 3 import ( 4 "fmt" 5 "net" 6 ) 7 8 // IpFormat formats the IP correctly, so we don't provide IPv6 address in an IPv4 format during node communication. We return the ip parameter as is if it's an IPv4 address or a hostname. 9 func IpFormat(ip string) string { 10 ipObj := net.ParseIP(ip) 11 // Return the ip/host as is if it's either a hostname or an IPv4 address. 12 if ipObj == nil || ipObj.To4() != nil { 13 return ip 14 } 15 16 return fmt.Sprintf("[%s]", ip) 17 }