Closed Kvaz1r closed 6 years ago
@Kvaz1r I think the range and current for loop doing the same, see the reason:
package main
import (
"fmt"
"github.com/davecgh/go-spew/spew"
)
func main() {
list := []struct {
Name string
}{
{
"Tom",
},
{
"Jane",
},
{
"Joe",
},
}
for _, l := range list {
spew.Dump(&l) // copy object to the same memory address
}
fmt.Println("=================================")
for i := 0; i < len(list); i++ {
l := list[i] // declare and initialize new variable, which also copy the object, unless you put reference (l := &list[i])
spew.Dump(&l)
}
fmt.Println("=================================")
spew.Dump(list)
}
Also the
queries
slice contains small amount of information
@thedevsaddam yes, I written this above:
The way that I made in my PR not very accurate and should be replaced into this one as written in description to rangeValCopy.
for i := range xs {
x := &xs[i]
...
}
@Kvaz1r the for loop is not needed as the the slice will be always small. It contains only queries passed by user. I'll revert the loop to for range. I'll keep helper changes. Thank you for the PR 👍
go-critic linter found some issues , here corresponding log:
In #18 I propose fixing for them
Thanks, good point. The way that I made in my PR not very accurate and should be replaced into this one as written in description to rangeValCopy.