fatcontext/contrib/example.go
2024-03-27 19:53:02 +01:00

21 lines
324 B
Go

package contrib
import "context"
func ok() {
ctx := context.Background()
for i := 0; i < 10; i++ {
ctx := context.WithValue(ctx, "key", i)
_ = ctx
}
}
func notOk() {
ctx := context.Background()
for i := 0; i < 10; i++ {
ctx = context.WithValue(ctx, "key", i) // "context not shadowed in loop"
_ = ctx
}
}