append result not assigned to the same slice
117 dayName := timeutil.Strftime(&refDate, "%a")
118 dayName = strings.ToLower(dayName)
119 today := stringMatchesListIndex(dayName, weekdays)
120 twoWeeks := append(weekdays, weekdays...)121 dayOffset := today - stringMatchesListIndex(ref[:3], twoWeeks)
122 if dayOffset < 0 {
123 dayOffset += 7
Description
The builtin function append
returns the updated slice after the append operation.
This resulting slice is usually assigned back to the same variable that contained
the original slice to which new values were appended.
Bad practice
x = []int{1, 3, 5}
append(x, 7) // returns the value []int{1, 3, 5, 7}. This is usually assigned back to x
x := []int{}
y := []int{}
x = append(y, 1) // possibly wrong
Recommended
x = []int{1, 3, 5}
x = append(x, 7)
x := []int{}
y := []int{}
y = append(y, 1) // append 1 to y