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
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+27.4k Golang : Convert CSV data to JSON format and save to file
+11.1k Golang : Fix go.exe is not compatible with the version of Windows you're running
+26.9k Golang : Force your program to run with root permissions
+9.4k Golang : Generate EAN barcode
+5.9k AWS S3 : Prevent Hotlinking policy
+22.9k Golang : Gorilla mux routing example
+6.5k Elasticsearch : Shutdown a local node
+9.5k Golang : Accessing content anonymously with Tor
+6.7k Golang : Skip or discard items of non-interest when iterating example
+13.5k Golang : How to get year, month and day?