github-vet / github-vet/rangeloop-pointer-findings
nullboundary/socialhardware: helpers.go; 52 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.