title: How to use next available port in http.ListenAndServe
body: <p>I wrote a simple web server to listen on port 8080. But I don't want to use a hard coded port number. What I want is that my server listen on any available port. And I want to know that on what port number my web server is listening.</p>
  
  <p>My code is given bellow:</p>
  
  <pre><code>package main
  
  import (
      "net/http"
  )
  
  func main() {       
      http.HandleFunc("/", handler)
      http.ListenAndServe(":8080", nil)
  
  }
  </code></pre>