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

uadmin/uadmin: static_handler.go; 26 LoC

Open
#17,705 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 [uadmin/uadmin](https://www.github.com/uadmin/uadmin) at [static_handler.go](https://github.com/uadmin/uadmin/blob/d5dfd4d360e4eccb4a881bc5fe71d65affb14847/static_handler.go#L32-L57)

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 k used in defer or goroutine at line 50

[Click here to see the code in its original context.](https://github.com/uadmin/uadmin/blob/d5dfd4d360e4eccb4a881bc5fe71d65affb14847/static_handler.go#L32-L57)

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

```go
for k := range staticABTests {
if k == r.URL.Path && len(staticABTests[k]) != 0 {
index := getABT(r) % len(staticABTests[k])
r.URL.Path = staticABTests[k][index].v

// Calculate number of seconds until midnight if no calculated yet
if midnightDelta == 0 {
midnight := time.Now()
midnight = time.Date(midnight.Year(), midnight.Month(), midnight.Day(), 0, 0, 0, 0, midnight.Location())
midnightDelta = int(midnight.Sub(time.Now()).Seconds())
}
// Add a header to expire the satic content at midnigh
w.Header().Add("Cache-Control", "private, max-age="+fmt.Sprint(midnightDelta))
modTime = time.Now()
ab = true

go func() {
abTestsMutex.Lock()
t := staticABTests[k]
t[index].imp++
staticABTests[k] = t
abTestsMutex.Unlock()
}()
break
}
}

```

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: d5dfd4d360e4eccb4a881bc5fe71d65affb14847

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.