title: Multiple response.WriteHeader calls
body: <p>I am new to go and have difficulty rendring templates. </p>
  
  <p>Here is my functions that are to generate template:</p>
  
  <p>base.html</p>
  
  <pre><code>//Render templates for the given name, template definition and data object
  func renderTemplate(w http.ResponseWriter, name string, template string, viewModel interface{}) {
      // Ensure the template exists in the map.
      tmpl, ok := templates[name]
      if !ok {
          http.Error(w, "The template does not exist.", http.StatusInternalServerError)
      }
      err := tmpl.ExecuteTemplate(w, template, viewModel)
      if err != nil {
      log.Printf("temlate error here")
          http.Error(w, err.Error(), http.StatusInternalServerError)
      }
  }
  
  
   func EditNote(w http.ResponseWriter, r *http.Request) {
      //var viewModel models.EditChnl
      vars := mux.Vars(r)
      //ch := bson.M{"id": "Ale"}
      title := vars["title"]
      log.Printf("%v\n", title)
      session, err := mgo.Dial("localhost")
      if err != nil {
        panic(err)
      }
          defer session.Close()
          session.SetMode(mgo.Monotonic, true)
          c := session.DB("tlgdb").C("chnls")
          log.Printf("title is %s \n", title)
          var result  []models.Chnl
          err = c.Find(bson.M{"title": "xxx"}).All(&amp;result)
          log.Printf("%v\n", result)
  
          if err != nil {
            log.Printf("doc not found")
            log.Fatal(err)
            return
          }
      renderTemplate(w, "edit", "base", result)
  }
  </code></pre>
  
  <p>And here are the templates:</p>
  
  <pre><code>{{define "base"}}
  &lt;html&gt;
    &lt;head&gt;
      {{template "head" .}}
    &lt;/head&gt;
    &lt;body&gt;
  
      {{template "body" .}}
  
    &lt;/body&gt;
  &lt;/html&gt;
  {{end}}
  </code></pre>
  
  <p>edit.thml</p>
  
  <pre><code>{{define "head"}}&lt;title&gt;Edit Note&lt;/title&gt;{{end}}
  {{define "body"}}
  &lt;h1&gt;Edit Note&lt;/h1&gt;
  &lt;form action="/chnls/update/{{.Title}}" method="post"&gt;
  &lt;p&gt;Title:&lt;br&gt; &lt;input type="text" value="{{.Title}}" name="title"&gt;&lt;/p&gt;
  &lt;p&gt;Description:&lt;br&gt; &lt;textarea rows="4" cols="50" name="description"&gt;{{.Description}}&lt;/textarea&gt; &lt;/p&gt;
  &lt;p&gt;&lt;input type="submit" value="submit"/&gt;&lt;/p&gt;
  &lt;/form&gt;
  {{end}}
  </code></pre>
  
  <p>The objects to render are:</p>
  
  <pre><code>type Chnl struct {
      Id    bson.ObjectId `json:"id"  bson:"_id,omitempty"`
      Title       string
      Description string
      CreatedOn   time.Time
      Creator     string
      Visits  int
      Score       int
  }
  </code></pre>
  
  <p>The object that I'm trying to render exists in mongodb and I can print it out in console:</p>
  
  <pre><code>[{ObjectIdHex("56cc4493bc54f4245cb4d36b") sometitle blabla 2016-02-23 12:37:55.972 +0100 CET blabla 0 0}]
  </code></pre>
  
  <p>However I get this error:</p>
  
  <pre><code>temlate error here
  http: multiple response.WriteHeader calls
  </code></pre>
  
  <p>I'm wondering what is wrong here and how to fix it?</p>