Below is the code snippet where i have declared a for loop and getting index and box from the array of boxes. I am using the same index below in the if else block, but the golangci-lint is complaining about the variable index unused
func createMap(action string, boxes []Box, ratesMap FeeMap) []RateRes {
resp := make([]RateRes, len(boxes))
overrideKey := fmt.Sprintf("%s-*", action)
for index, box := range boxes {
key := fmt.Sprintf("%s-%s", action, boxes.label)
rate, hasDefault := ratesMap[key]
if hasDefault {
resp[index] = RateRes{
Code: rate.Code,
Label: box.label,
}
} else {
resp[index] = RateRes{
Code: RatesMap[overrideKey].Code,
Label: box.label,
}
}
}
return resp
}
The exact error i am getting is : Error: index declared but not used (typecheck)
Please suggest how to overcome this issue, which does not seem an issue.
In your
for loop
initialization statement you declare thebox
variable and it hasn't been used in the codes after that.please remove it if you are not using it change it like this.