Sorry, I made a mistake when copy paste :) Actually we can assume above code as go func() { ... } Because I want to reference of w variable which is the type of http.ResponseWrite. My actual problem is w.wr is nil inside go routine. I can post the code today but I can not access the code right now.
On Monday, July 15, 2019 at 9:32:54 PM UTC+3, Burak Serdar wrote: > > On Mon, Jul 15, 2019 at 12:14 PM <hasangen...@gmail.com <javascript:>> > 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 golan...@googlegroups.com <javascript:>. > > 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/5409eefa-3fa9-4502-9e39-51849037f58d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.