title: Golang: Automatic Refresh of a HTTP Page
body: <p>I have a HTTP page getting executed using Go programming language. The function in GO looks like this:</p>
  
  <pre><code>func main(){
      ...
      http.HandleFunc("/Page", func(w http.ResponseWriter, r *http.Request) {
          t:=template.New("New template")
          child_template := t.New("New child template")
          _, _ = child_template.Parse(output)  // output is from the omitted code
          t, err = t.ParseFiles("HTML_template.html")
          _ = t.ExecuteTemplate(w, "HTML_template.html", output)
      }
  }
  </code></pre>
  
  <p>How do I make /Page refreshes by itself? I have tried the following, but it doesn't work.</p>
  
  <pre><code>func main(){
      ...
      http.HandleFunc("/Page", func(w http.ResponseWriter, r *http.Request) {
          for{
              t:=template.New("New template")
              child_template := t.New("New child template")
              _, _ = child_template.Parse(output)  // output is from the omitted code
              t, err = t.ParseFiles("HTML_template.html")
              _ = t.ExecuteTemplate(w, "HTML_template.html", output)
  
              time.Sleep(time.Millisecond*100)
          }
      }
  }
  </code></pre>
  
  <p>I am trying to make a dynamic graph that plots the number of incoming data per second. If I keep making the browser refreshes, the axis will get reloaded too and it looks ugly. The HTML_template.html looks like this</p>
  
  <pre><code>&lt;script type = "text/javascript"&gt;
      function plot(){
          ...
          var data = [{{template "New child template"}}];
          ...
      }
      setInterval(func(){plot()},500);
  &lt;/script&gt;
  </code></pre>