title: http.HandleFunc invokes root handler 3 times per request
body: <pre><code>package main
  
  import (
      "fmt"
      "io"
      "html/template"
      "net/http"
      "log"
  )
  
  type pageFunc func() (string, interface{})
  
  func thread() (string, interface{}) {
      return "thread", nil
  }
  
  func main() {
  
      t := template.New("main")
      t.ParseGlob("templates/*.xhtml")
  
      respond := func(f pageFunc) http.HandlerFunc {
          fmt.Println("respond 1")
  
          return func(w http.ResponseWriter, r *http.Request) {
              fmt.Println("respond 2")
              name, data := f()
              t.ExecuteTemplate(w, name, data)
          }
      }
  
      http.HandleFunc("/", respond(thread))
      err := http.ListenAndServe(":7842", nil)
      if err != nil {
          log.Fatal("ListenAndServe: ", err)
      }
  }
  </code></pre>
  
  <p>Starting the program above and sending a single request to <code>http://localhost:7842/</code> causes the console to output:</p>
  
  <pre><code>respond 1
  respond 2
  respond 2
  respond 2
  </code></pre>
  
  <p>It only appears to invoke the handler a single time if I comment out:</p>
  
  <pre><code>name, data := f()
  t.ExecuteTemplate(w, name, data)
  </code></pre>
  
  <p>In that case I just get:</p>
  
  <pre><code>respond 1
  respond 2
  </code></pre>
  
  <p>This is completely beyond my comprehension. How would calling t.ExecuteTemplate cause the function it's invoked from to run more than once? Even more bizarre (to me, at least) is that if I change the path slightly, like so,</p>
  
  <pre><code>http.HandleFunc("/a", respond(thread))
  </code></pre>
  
  <p>... it once again only fires the handler function once, even with the templating function uncommented. What is happening?</p>
  
  <p>The template in question, if it interests anyone:</p>
  
  <pre><code>{{ define "thread" }}&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
      &lt;head&gt;
          &lt;title&gt;test thread page&lt;/title&gt;
          &lt;link rel="stylesheet" type="text/css" href="/static/board.css" /&gt;
          &lt;script type="text/javascript" src="/static/general.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
  
      &lt;body&gt;
          &lt;h1&gt;hello, world.&lt;/h1&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  {{ end }}
  </code></pre>