Golang net.JoinHostPort() function example
package net
Golang net.JoinHostPort() function usage example
Example 1:
...
var ip net.IP
switch addr.family {
case syscall.AF_INET:
ip = addr.data[2:6]
default:
return "", errors.New("unrecognized address family")
}
port := int(addr.data[0])<<8 + int(addr.data[1])
hostnameWithPort := net.JoinHostPort(ip.String(), strconv.Itoa(port)), nil
return hostnameWithPort
Example 2:
conn, err := net.DialTimeout("tcp", net.JoinHostPort(address, "22"), time.Duration(5) * time.Second)
if err != nil {
// ...
}
Reference :
Advertisement
Something interesting
Tutorials
+12.5k Golang : Forwarding a local port to a remote server example
+22k Fix "Failed to start php5-fpm.service: Unit php5-fpm.service is masked."
+5.7k List of Golang XML tutorials
+43.2k Golang : Convert []byte to image
+5.5k Clean up Visual Studio For Mac installation failed disk full problem
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+12.3k Golang : Display list of countries and ISO codes
+16.6k Golang : Delete files by extension
+6.2k Golang : Process non-XML/JSON formatted ASCII text file example
+5.9k Golang : Denco multiplexer example
+10.3k Golang : Detect number of faces or vehicles in a photo
+33k Golang : How to check if a date is within certain range?