flusher, ok := w.(http.Flusher)// w.wr is io.Writer herefor _, gateway := range app.Gateway {
go func(w http.ResponseWriter) {
// w.wr is nil here
tmpl, err := template.New(gateway.Name).Parse(gateway.Content)
if err != nil {
panic("An Error occured when parsing html")
return
}
tmpl.Execute(w, "")
defer flusher.Flush()
}()
}
Why w.wr is nil inside the function ? When i use function as non routine it works fine but i want to use the function as go routine.
> To unsubscribe from this group and stop receiving emails from it, send an email to golan...@googlegroups.com.
This is my original code.
outside of the go routine w variable is
But inside the go routine
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)
}
}
This is my original code.outside of the go routine w variable is
But inside the go routine
--
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...@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.
<Screen Shot 2019-07-16 at 20.57.35.png>
<Screen Shot 2019-07-16 at 20.58.17.png>
This is my original code.
--
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...@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.