Yes it will work as "x" is within scope. https://play.golang.org/p/dhBahtIVGb
On Tuesday, 7 November 2017 14:42:47 UTC+5:30, Abhijit Desai wrote: > > I want to log MyStruct value in "defer + go routine" so that logging > will not affect total execution time of the the request.... which works > fine as serving request is not taking 5+seconds... > > my question is.. will I get value of "x" in "defer + go routine" as main > module already exit > > r.POST("/search", func(c *gin.Context) { > var x MyStruct > x := new(MyStruct) > defer func() { > go func() { > time.Sleep(5000 * time.Millisecond) // for > checking if main request is waiting for this... > log(x) > }() > }() > > if c.Bind(&x) == nil { > DoWork() > } > } > -- 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. For more options, visit https://groups.google.com/d/optout.