github-vet / github-vet/rangeloop-pointer-findings
xiyy/musicClawler: crawler.go; 57 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [xiyy/musicClawler](https://www.github.com/xiyy/musicClawler) at [crawler.go](https://github.com/xiyy/musicClawler/blob/0254450c4f4db4430dc1c17cc47dbe22caf122bc/crawler.go#L211-L267)
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 v used in defer or goroutine at line 224
[Click here to see the code in its original context.](https://github.com/xiyy/musicClawler/blob/0254450c4f4db4430dc1c17cc47dbe22caf122bc/crawler.go#L211-L267)
Click here to show the 57 line(s) of Go which triggered the analyzer.
```go
for _, v := range songList {
if v != nil {
var dir = "E:/music/"
if v.Singer != "" {
dir = dir + v.Singer
createFile(dir)
log.Println("create singer dir:", dir)
} else {
log.Println("song.Singer is null")
return errors.New("song.Singer is null")
}
if v.RequestMp3Url != "" {
go func() {
mp3UrlRes, err := http.Get(v.RequestMp3Url)
if err != nil {
log.Println(err.Error())
return
}
var mp3UrlResBytes []byte
mp3UrlResBytes, _ = ioutil.ReadAll(mp3UrlRes.Body)
defer mp3UrlRes.Body.Close()
mp3Url := string(mp3UrlResBytes)
log.Println("mp3Url:", mp3Url)
if mp3Url != "" {
filePath := dir + "/" + v.Name + "_" + v.Music_id + "_" + v.Special + ".mp3"
log.Println(filePath)
downLoad(mp3Url, filePath)
}
}()
}
if v.ReqeustAacUrl != "" {
go func() {
aacUrlRes, err := http.Get(v.ReqeustAacUrl)
if err != nil {
log.Println(err.Error())
return
}
var aacUrlResBytes []byte
aacUrlResBytes, _ = ioutil.ReadAll(aacUrlRes.Body)
defer aacUrlRes.Body.Close()
aacUrl := string(aacUrlResBytes)
log.Println("aacUrl:", aacUrl)
if aacUrl != "" {
filePath := dir + "/" + v.Name + "_" + v.Music_id + "_" + v.Special + ".aac"
log.Println(filePath)
downLoad(aacUrl, filePath)
}
}()
}
}
time.Sleep(time.Millisecond * 200)
}
```
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: 0254450c4f4db4430dc1c17cc47dbe22caf122bc
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.