title: How do you send websocket data after a page is rendered in Golang?
body: <p><br/>
  I am new to Golang and am trying to send data using web-sockets to a page. I have a handler and I want to be able to serve a file and after it is rendered send it a message. This is some code that I have now.</p>
  
  <pre><code>package main
  
  import (
      "github.com/gorilla/websocket"
      "log"
      "fmt"
      "net/http"
  )
  
  var upgrader = websocket.Upgrader{
      ReadBufferSize:  1024,
      WriteBufferSize: 1024,
  }
  
  func serveRoot(w http.ResponseWriter, r *http.Request) {
      http.ServeFile(w, r, "views/index.html")
      _, err := upgrader.Upgrade(w, r, nil)
      if err != nil {
          log.Println(err)
          return
      }
  }
  
  func main() {
      http.HandleFunc("/", serveRoot)
      fmt.Println("Started")
      if err := http.ListenAndServe(":9090", nil); err != nil {
          log.Fatal("ListenAndServe:", err)
      }
  }
  </code></pre>
  
  <p>The problem is that using the <code>gorilla</code> library I have no idea how to send data and I am getting some output when I load the page.</p>
  
  <pre><code>2018/01/23 08:35:24 http: multiple response.WriteHeader calls
  2018/01/23 08:35:24 websocket: the client is not using the websocket protocol: 'upgrade' token not found in 'Connection' header
  2018/01/23 08:35:24 http: multiple response.WriteHeader calls
  2018/01/23 08:35:24 websocket: 'Origin' header value not allowed
  </code></pre>
  
  <p><strong>Intention:</strong> Send some data after the page is rendered, then <em>(later)</em> hook it up to <code>stdin</code>/<code>stderr</code><br/>
  <strong>Disclaimer:</strong> I am just learning to code, so it would be a great help is you could take that into consideration and not be too vague.</p>