Some confusion may arise when using closures with concurrency. Consider the following program:

func main() {
    done := make(chan bool)

    values := []string{"a", "b", "c"}
    for _, v := range values {
        go func() {
            fmt.Println(v)
            done <- true
        }()
    }

    // wait for all goroutines to complete before exiting
    for _ = range values {
        <-done
    }
}
To bind the current value of v to each closure as it is launched, one must modify the inner loop to create a new variable each iteration. One way is to pass the variable as an argument to the closure:

for _, v := range values {
        go func(u string) {
            fmt.Println(u)
            done <- true
        }(v)
    }
Even easier is just to create a new variable, using a declaration style that may seem odd but works fine in Go:

for _, v := range values {
        v := v // create a new 'v'.
        go func() {
            fmt.Println(v)
            done <- true
        }()
    }

Recommend

Go Frequently Asked Questions (FAQ) Functions and Methods Why do T and *T have different method sets?

Go Frequently Asked Questions (FAQ) Pointers and Allocation What is the size of an int on a 64 bit machine?

Go Frequently Asked Questions (FAQ) Pointers and Allocation Should I define methods on values or pointers?

Go Frequently Asked Questions (FAQ) Pointers and Allocation When should I use a pointer to an interface?

Go Frequently Asked Questions (FAQ) Writing Code How should I manage package versions using go get ?

Go Frequently Asked Questions (FAQ) Writing Code Why does go get use HTTPS when cloning a repository?

Frequently Asked Questions (FAQ) Values How do constants work in Go?

Frequently Asked Questions (FAQ) Types Why does Go not have covariant result types?

Go Frequently Asked Questions (FAQ) Types Why is my nil error value not equal to nil?

Go Frequently Asked Questions (FAQ) Types Can I convert []T1 to []T2 if T1 and T2 have the same underlying type?

Go Frequently Asked Questions (FAQ) Types Can I convert a []T to an []interface{}?

Go Frequently Asked Questions (FAQ) Types Why doesn't type T satisfy the Equal interface?

Go Frequently Asked Questions (FAQ) Types How can I guarantee my type satisfies an interface?

Go 1.9 Release Notes Changes to the language

Effective Go A web server

Effective Go Errors Recover

Effective Go Errors Panic

Effective Go Errors

Effective Go Concurrency A leaky buffer

Effective Go Concurrency Parallelization

Effective Go Concurrency Channels of channels

Effective Go Concurrency Channels

Effective Go Concurrency Goroutines

Effective Go Embedding

Effective Go The blank identifier Interface checks

Effective Go The blank identifier Import for side effect

Effective Go The blank identifier Unused imports and variables

Effective Go The blank identifier The blank identifier in multiple assignment

Effective Go Interfaces and other types Interfaces and methods

Effective Go Interfaces and other types Generality

Effective Go Interfaces and other types Interface conversions and type assertions

Effective Go Interfaces and other types Conversions

Effective Go Interfaces and other types Interfaces

Effective Go Methods Pointers vs. Values

Effective Go Initialization The init function

Effective Go Initialization Variables

Effective Go Initialization Constants

Effective Go Data Append