github-vet / github-vet/rangeloop-pointer-findings
hbakhtiyor/omise-go-challenge: donate.go; 54 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [hbakhtiyor/omise-go-challenge](https://www.github.com/hbakhtiyor/omise-go-challenge) at [donate.go](https://github.com/hbakhtiyor/omise-go-challenge/blob/0acba004c4ae92506133d2b4a95b18c651b6007b/donate.go#L79-L132)
Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.
> range-loop variable fileName used in defer or goroutine at line 96
[Click here to see the code in its original context.](https://github.com/hbakhtiyor/omise-go-challenge/blob/0acba004c4ae92506133d2b4a95b18c651b6007b/donate.go#L79-L132)
Click here to show the 54 line(s) of Go which triggered the analyzer.
```go
for _, fileName := range files {
options.Extension = filepath.Ext(fileName)
if options.Extension == ".tsv" {
options.Comma = '\t'
}
reader, err := getReader(fileName)
if err != nil {
fmt.Printf("%v: %v\n", fileName, err)
continue
}
chPayment := make(chan *Payment)
go func(reader io.ReadCloser) {
if err := processCSV(reader, chPayment, options); err != nil {
fmt.Printf("%v: %v\n", fileName, err)
}
}(reader)
result := &DonationResult{TopPayments: []*Payment{{}, {}, {}}, Currency: DefaultCurrency}
fmt.Println("performing donations...")
var wg sync.WaitGroup
cpus := runtime.NumCPU()
for payment := range chPayment {
result.sortTopPayments(payment)
result.TotalPayments++
wg.Add(1)
go func(payment *Payment) {
defer wg.Done()
if succeed, err := createTokenAndCharge(client, payment); err != nil {
log.Fatal(err)
} else if succeed {
result.SuccessSum += payment.Amount
} else {
result.FailSum += payment.Amount
}
}(payment)
if result.TotalPayments%cpus == 0 {
wg.Wait()
result.printSummary(true)
}
}
wg.Wait()
result.cleanSummary()
fmt.Printf("done.\n")
result.printSummary(false)
}
```
Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.
commit ID: 0acba004c4ae92506133d2b4a95b18c651b6007b
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.