package main import ( "net" "fmt" ) func listenOn(protocol, port string) { fmt.Println("\nAttempting to listen on protocol", protocol, "and port", port) l, e := net.Listen(protocol, port) if e != nil { fmt.Println("FAILURE:", e.Error()) return } else { fmt.Println("SUCCESS: Listening on", l.Addr()) l.Close() } } func main() { listenOn("tcp", ":http") // this will auto-detect and bind to available protocol... listenOn("tcp4", ":http") listenOn("tcp6", ":http") }