_, err := strconv.ParseInt(host, 10, 64)
if err == nil {
hp.IpAddress = host
} else {
hp.HostName = dbhost
}
With host = sealinuxvm11 I'm getting
error strconv.ParseInt: parsing " sealinuxvm11 ": invalid syntax
and with host = 192.168.24.10
strrconv.ParseInt: parsing " 192.168.24.10": invalid syntax
An IP Address should be parsed as a string. I use the net package's ParseIP to determine whether a given string is an IP or a host
addr := net.ParseIP(host)
if addr == nil {
hp.IPAddress = host
} else {
hp.HostName = host
}
this is may set hostname with an invalid value. Check to make sure that host name is a valid host name if net.ParseIP
returns an error. Would use
hostName, err := net.LookupHost(host)
if len(hostName) > 0{
if hostName[0] == hp.HostName{
}
}
to determine if the host name is valid
Like Kosik pointed out in the comments there are definitely better and faster ways to determine if a host name is valid. I recommend you do some research into how that can be achieved