ALL


  Go 1.22 for-range Fix and go.mod Dependency

With the release of Go 1.22, the Go team addressed a long-standing issue with the for-range loop variable scoping, which had been a common pitfall for developers writing concurrent code. Specifically, the problem was that the loop variable in a for-range loop was reused across iterations, leading to unexpected behavior when closures were involved.The Issue Before Go 1.22Consider the following example:package forangeimport "fmt"func Do() { done := make(chan bool) values := []string{"a", "b", "c"} for _, v := range values { go func() { fmt.Println(v) // Prints unexpect...

15 0       GOLANG FOR RANGE GO.MOD GO 1.22