github-vet / github-vet/rangeloop-pointer-findings

dekuer/ChengYuApp: ChengYuApp/DownIdiomJson/main.go; 18 LoC

Open
#12,781 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [dekuer/ChengYuApp](https://www.github.com/dekuer/ChengYuApp) at [ChengYuApp/DownIdiomJson/main.go](https://github.com/dekuer/ChengYuApp/blob/4c0dc493dd91461adcca14374866efaf9ed62352/ChengYuApp/DownIdiomJson/main.go#L82-L99)

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 84

[Click here to see the code in its original context.](https://github.com/dekuer/ChengYuApp/blob/4c0dc493dd91461adcca14374866efaf9ed62352/ChengYuApp/DownIdiomJson/main.go#L82-L99)

Click here to show the 18 line(s) of Go which triggered the analyzer.

```go
for _, v := range dataSlice {
go func() {
title := v.(map[string]interface{})["title"].(string) //此时得到的是成语名字
idiomInfo := GetJson(`http://route.showapi.com/1196-2?showapi_appid=91194&showapi_sign=9f081d50fd6b40fba69b24c99cc5f7ac&keyword=` + title) //返回的是相应成语的信息
err = json.Unmarshal([]byte(idiomInfo), &tempMap2)
if err != nil {
fmt.Println(err)
}
dataSlice2 := tempMap2["showapi_res_body"].(map[string]interface{})["data"].(map[string]interface{}) //成语的信息
idiom.Title = dataSlice2["title"].(string) //将数据存进结构体
idiom.Spell = dataSlice2["spell"].(string)
idiom.Samples = dataSlice2["samples"].(string)
idiom.Derivation = dataSlice2["derivation"].(string)
idiom.Content = dataSlice2["content"].(string)
idiomsMapBase[title] = idiom //成语名字对应的是所有的信息
}()
time.Sleep(1 * time.Second)
}

```

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: 4c0dc493dd91461adcca14374866efaf9ed62352

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.