On Mon, Jul 15, 2019 at 12:14 PM <hasangenc.istan...@gmail.com> wrote:
>
> flusher, ok := w.(http.Flusher)
>
>
> // w.wr is io.Writer here
>
>
> for _, 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.

This isn't valid code. The goroutine is declared with a w arg, but it
is not called with the parameter.

Assuming you intended to pass the w declared outside the for loop: is
it possible that the whole thing is inside another for-loop, and w is
the loop variable?

for _,w:=range ... {
  // your code here
}

If that's the case, just add a w:=w at the top of the for loop:

for _,w:=range ... {
  w:=w
  // your code here
}

If that's not the case, maybe posting code that compiles might help.

>
> --
> 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/f167b667-fb31-4c20-bf44-f6a114b21c62%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
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/CAMV2RqrnN37x97Uy4OFusTHZNR5%2BBdF6ROxyYQQwTDVJd-wT4A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to