github-vet / github-vet/rangeloop-pointer-findings
nullboundary/socialhardware: helpers.go; 52 LoC
- Vorherrschende Sprache
- Keine Sprachdaten
- Sterne
- 0
- Forks
- 0
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
Found a possible issue in [nullboundary/socialhardware](https://www.github.com/nullboundary/socialhardware) at [helpers.go](https://github.com/nullboundary/socialhardware/blob/fcd29718ded99ebc3ed42057aae744d0c909accd/helpers.go#L70-L121)
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 trigger used in defer or goroutine at line 78
[Click here to see the code in its original context.](https://github.com/nullboundary/socialhardware/blob/fcd29718ded99ebc3ed42057aae744d0c909accd/helpers.go#L70-L121)
Click here to show the 52 line(s) of Go which triggered the analyzer.
```go
for _, trigger := range triggerList {
//log.Printf("ID: %s Trigger: if %s then %s \n", trigger.TriggerID, trigger.TriggerCondition, trigger.Triggerhook.URL)
if triggerMatch(trigger, data) {
//every client request in a seperate goroutine (some could be slow to return)
go func() {
u, err := url.Parse(trigger.URL)
if err != nil {
log.Printf("[ERROR] %s", err)
return
}
//TODO: maybe localhost shouldn't be allowed after deployment ?
if u.Scheme == "localhost" {
u.Scheme = "http://localhost"
}
log.Println("URL: ", u)
//if trigger.Body
bytesBody, err := trigger.Body.MarshalJSON()
if err != nil {
log.Printf("[ERROR] %s", err)
}
bodyReader := bytes.NewReader(bytesBody)
//var jsonStr = []byte(`{"title":"Buy cheese and bread for breakfast."}`)
req, err := http.NewRequest(trigger.Method, u.String(), bodyReader)
req.Header.Set("Authorization", "0e1766cb9a519d3")
header := strings.Split(trigger.Headers, ":")
headerKey := strings.TrimSpace(header[0])
headerValue := strings.TrimSpace(header[1])
req.Header.Add(headerKey, headerValue)
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
log.Printf("[ERROR] %s", err)
return
}
defer resp.Body.Close()
log.Println("response Status:", resp.Status)
log.Println("response Headers:", resp.Header)
body, _ := ioutil.ReadAll(resp.Body)
log.Println("response Body:", string(body))
}()
}
}
```
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: fcd29718ded99ebc3ed42057aae744d0c909accd
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Beginne mit dem Lesen von helpers.go in den Zeilen 70-121, insbesondere der range-Schleife und der bei Zeile 78 gemeldeten Goroutine, und vergleiche dann den Befund des Analyzers mit dem umgebenden Trigger-Dispatch. Bestätige, ob das Verhalten ein Bug, mitigiert oder wünschenswert ist, und hinterlasse die entsprechende Reaktion; in der Issue ist keine Testdatei angegeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- go
- Bereich
- backend
- Issue-Typ
- Bug
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 50/100