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
+21.9k Golang : Use TLS version 1.2 and enforce server security configuration over client
+3.7k Java : Random alphabets, alpha-numeric or numbers only string generator
+18.8k Golang : How to make function callback or pass value from function as parameter?
+11.9k Golang : Convert(cast) bigint to string
+9k Golang : How to use Gorilla webtoolkit context package properly
+12.9k Python : Convert IPv6 address to decimal and back to IPv6
+7.1k Golang : Array mapping with Interface
+29.1k Golang : Get first few and last few characters from string
+15.7k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+11.7k Golang : Calculations using complex numbers example
+15.2k Golang : Get HTTP protocol version example
+28.5k Golang : Change a file last modified date and time