Before: ``` % sshpiperd pipe list donatas -> root@2a02:4231:face:1001:1610:931c:2980:9d9d:22 ``` After: ``` % sshpiperd pipe list donatas -> root@[2a02:4231:face:1001:1610:931c:2980:9d9d]:22 ```
17 lines
231 B
Go
17 lines
231 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net"
|
|
"strings"
|
|
)
|
|
|
|
func FormatIPAddress(host string) string {
|
|
ip4 := net.ParseIP(host).To4()
|
|
|
|
if ip4 != nil || !strings.Contains(host, ":") {
|
|
return host
|
|
}
|
|
|
|
return fmt.Sprintf("[%s]", host)
|
|
}
|