mirror of
https://github.com/Crocmagnon/fatcontext.git
synced 2024-11-21 15:38:08 +01:00
add readme
This commit is contained in:
parent
f6a431c247
commit
75b2beb848
2 changed files with 31 additions and 1 deletions
30
README.md
Normal file
30
README.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
# foreshadow
|
||||
|
||||
`foreshadow` is a Go linter which detects un-shadowed contexts in loops.
|
||||
They can lead to performance issues, as documented here: https://gabnotes.org/fat-contexts/
|
||||
|
||||
## Example
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
```
|
|
@ -15,7 +15,7 @@ func notOk() {
|
|||
ctx := context.Background()
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
ctx = context.WithValue(ctx, "key", i)
|
||||
ctx = context.WithValue(ctx, "key", i) // "context not shadowed in loop"
|
||||
_ = ctx
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue