title: How to make a websocket client wait util the server is running?
body: <p>I want to create a websocket client that waits until the server is running. If the connection is closed by the server it should reconnect.</p>
  
  <p>What I tried does not work and my code exits with a runtime error:</p>
  
  <p><code>panic: runtime error: invalid memory address or nil pointer dereference</code></p>
  
  <pre><code>func run() {
    origin := "http://localhost:8080/"
    url := "ws://localhost:8080/ws"
  
    ws, err := websocket.Dial(url, "", origin)
  
    if err != nil {
        fmt.Println("Connection fails, is being re-connection")
        main()
    }
  
    if _, err := ws.Write([]byte("something")); err != nil {
      log.Fatal(err)
    }
  }
  </code></pre>