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.8k Golang : Reverse a string with unicode
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+25.9k Golang : How to read integer value from standard input ?
+23.1k Golang : simulate tail -f or read last line from log file example
+20.5k Golang : Pipe output from one os.Exec(shell command) to another command
+14.5k Golang : How to determine if user agent is a mobile device example
+11.2k Golang : Fix - does not implement sort.Interface (missing Len method)
+3.7k Golang : Switch Redis database redis.NewClient
+8.1k Golang : How To Use Panic and Recover
+9.5k Golang : Accessing content anonymously with Tor
+13.6k Golang : Get user input until a command or receive a word to stop