title: How to fix a server failure when the client reloads the page?
body: <p>When the client reloads the page, the server issues an error -
  websocket: close 1001 (going away).
  When the client reloads the page, does not the websocket connection reconnect?
  I recently started studying programming, so please forgive if the question is stupid.
  Client code</p>
  
  <pre><code>var socket = new WebSocket("ws://localhost:8080/ws" );
  
  socket.onmessage = function (event) {
      DownloadScene(event)
  }
  
  function DownloadScene(event) {
      var data = JSON.parse(event.data)
      document.getElementById(data.id).innerHTML = data.body;
  }
  function  loadScene(scene) {
    var page = {
      query_type:"loadScene",
      data : {temp:scene}
  }
     var event = JSON.stringify(page);
     socket.send(event);
  }
  </code></pre>
  
  <p>I'm using the gorilla websocket library to build a connection.</p>
  
  <p>Server code</p>
  
  <pre><code>func WebSocketHandler(w http.ResponseWriter, r *http.Request) {
  
     conn, err := upGrader.Upgrade(w, r, nil)
  
     if err != nil {
        log.Println(err)
        return
     }
     for { webSocketHandler(conn)}
     defer conn.Close()
  }
  
  func webSocketHandler(conn *websocket.Conn) {
  
    println("new connect")
    err := conn.ReadJSON(&amp;query)
    if err != nil {
        log.Fatal(err)
        return
    }
    switch query.QueryType {
    case "loadScene" :
      err := json.Unmarshal(query.Data,&amp;frames)
      if err!= nil{
          log.Fatal(err)
      }
      var buf  bytes.Buffer
      data := frame.ExecuteTemplate(&amp;buf,"frame",nil)
      if data!=nil{
          log.Fatal(data)
      }
      res,e := json.Marshal(&amp;Frame{"scene",buf.String()})
      if e !=nil{
          log.Println(e)
      }
  
      errs := conn.WriteMessage(1,res)
      if err!=nil{
          log.Fatal(errs)
      }
   }
  }
  </code></pre>