At a guess, because your goroutine is running after the response handler has 
returned, and at that point the ResponseWriter isn’t valid any more.

//jb

On 16 Jul 2019, at 20:03, Hasan Genc 
<hasangenc.istan...@gmail.com<mailto:hasangenc.istan...@gmail.com>> wrote:


This is my original code.

outside of the go routine w variable is

<Screen Shot 2019-07-16 at 20.57.35.png><about:invalid#zClosurez>










But inside the go routine

<Screen Shot 2019-07-16 at 20.58.17.png><about:invalid#zClosurez>








I don't understand why. Anyone can help about this ?



func Make(w http.ResponseWriter, r *http.Request, app App) {
   runtime.GOMAXPROCS(4)

   flusher, ok := w.(http.Flusher)

   if !ok {
      panic("expected http.ResponseWriter to be an http.Flusher")
   }

   w.Header().Set("X-Content-Type-Options", "nosniff")

   tmpl, err := template.New("app").Parse(app.Page.Content)

   if err != nil {
      panic("An Error occured when parsing html")
      return
   }

   err = tmpl.Execute(w, "")

   if err != nil {
      panic("Error in Template.Execute")
   }

   flusher.Flush()

   for _, gateway := range app.Gateway {

      go func(gateway Gateway) {
         tmpl, err := template.New(gateway.Name).Parse(gateway.Content)

         if err != nil {
            panic("An Error occured when parsing html")
         }

         err = tmpl.Execute(w, "")

         if err != nil {
            panic(err)
         }

         defer flusher.Flush()
      }(gateway)
   }

}


--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
golang-nuts+unsubscr...@googlegroups.com<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/17998013-2d1b-4921-8fa4-061a5b217875%40googlegroups.com<https://groups.google.com/d/msgid/golang-nuts/17998013-2d1b-4921-8fa4-061a5b217875%40googlegroups.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
<Screen Shot 2019-07-16 at 20.57.35.png>
<Screen Shot 2019-07-16 at 20.58.17.png>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/30C32A72-BCAD-426F-964C-E2F6F8822342%40kastelo.net.
For more options, visit https://groups.google.com/d/optout.

Reply via email to