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
+18.6k Golang : Iterating Elements Over A List
+22.6k Generate checksum for a file in Go
+17.4k Golang : Check if IP address is version 4 or 6
+7.3k Golang : How to convert strange string to JSON with json.MarshalIndent
+14.3k Golang : Get uploaded file name or access uploaded files
+15.2k Golang : How to add color to string?
+8.1k Golang : Append and add item in slice
+5.9k Golang : Shuffle array of list
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+37.7k Golang : Comparing date or timestamp
+5.7k Fix yum-complete-transaction error
+11.2k Golang : How to pipe input data to executing child process?