This commit is contained in:
Marcus Efraimsson
2019-01-15 15:16:20 +01:00
parent d907b1ec6b
commit e08f61059b
3 changed files with 49 additions and 0 deletions
+27
View File
@@ -0,0 +1,27 @@
package util
import (
"net"
"strings"
)
// ParseIPAddress parses an IP address and removes port and/or IPV6 format
func ParseIPAddress(input string) string {
var s string
lastIndex := strings.LastIndex(input, ":")
if lastIndex != -1 {
s = input[:lastIndex]
}
s = strings.Replace(s, "[", "", -1)
s = strings.Replace(s, "]", "", -1)
ip := net.ParseIP(s)
if ip.IsLoopback() {
return "127.0.0.1"
}
return ip.String()
}