Golang net.SplitHostPort function example
package net
Golang net.SplitHostPort function usage example
package main
import (
"fmt"
"net"
)
func main() {
host,port,err:=net.SplitHostPort("socketloop.com:80")
if err != nil {
fmt.Println(err)
}
fmt.Println(host) // socketloop.com
fmt.Println(port) // 80
host1,port1,err1:=net.SplitHostPort("[socketloop.com:tcp]:8080")
if err1 != nil {
fmt.Println(err1)
}
fmt.Println(host1) // socketloop.com:tcp
fmt.Println(port1) // 8080
}
References :
http://golang.org/pkg/net/#SplitHostPort
https://www.socketloop.com/tutorials/golang-how-to-get-url-port
Advertisement
Something interesting
Tutorials
+17.6k Convert JSON to CSV in Golang
+5.4k Unix/Linux : How to archive and compress entire directory ?
+5.3k Python : Convert(cast) string to bytes example
+20.3k Golang : Check if os.Stdin input data is piped or from terminal
+7.3k Golang : alternative to os.Exit() function
+20.2k Golang : Compare floating-point numbers
+14.4k Golang : On enumeration
+5.1k Linux/Unix/MacOSX : Find out which application is listening to port 80 or use which IP version
+29.2k Golang : missing Git command
+5.4k How to check with curl if my website or the asset is gzipped ?
+22.1k Golang : Match strings by wildcard patterns with filepath.Match() function
+13.6k Golang : Strings comparison