Fix shadowing assignments inside closures (#5944)

When inside a closure, it is important to not accidentally assign
to variables declared outside the scope of the closure. Doing so
causes static analysis tools (such as `errcheck`) to be unable to
evaluate the lifetime of the variable, and unable to determine if
it is appropriately read from before being assigned to again.

Fix two instances where we assign to a variable declared in the
closure's enclosing scope, rather than declaring a new variable
with the same name.
This commit is contained in:
Aaron Gable 2022-02-16 14:33:17 -08:00 committed by GitHub
parent 3bb3421631
commit d1777c5fda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 2 additions and 2 deletions

View File

@ -189,7 +189,7 @@ func (c *WritingClient) StoreResponse(ctx context.Context, respBytes []byte, sho
metadataValue := metadataStruct.Marshal()
err = c.rdb.Watch(ctx, func(tx *redis.Tx) error {
err = tx.Set(ctx, responseKey, respBytes, ttl).Err()
err := tx.Set(ctx, responseKey, respBytes, ttl).Err()
if err != nil {
return fmt.Errorf("setting response: %w", err)
}

View File

@ -80,7 +80,7 @@ func main() {
}
http.Handle("/metrics", promhttp.Handler())
go func() {
err = http.ListenAndServe(*listenAddress, nil)
err := http.ListenAndServe(*listenAddress, nil)
if err != nil && err != http.ErrServerClosed {
log.Fatal(err)
}