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
+9.6k Golang : Read file with ioutil
+14.8k Golang : Find commonalities in two slices or arrays example
+4.7k Javascript : Access JSON data example
+26.7k Golang : How to check if a connection to database is still alive ?
+19.4k Golang : How to count the number of repeated characters in a string?
+11.6k Golang : Surveillance with web camera and OpenCV
+5.8k Linux : Disable and enable IPv4 forwarding
+7.7k Golang : Error reading timestamp with GORM or SQL driver
+7.7k Golang : Generate human readable password
+17.9k Golang : Simple client server example
+14.2k Golang : Chunk split or divide a string into smaller chunk example
+18.7k Golang : Iterating Elements Over A List