Empty slice literal of type "[]uint64" used to define "voterFollowers"
924 if learnerStore == leader {
925 continue
926 }
927 voterFollowers := []uint64{} 928 for _, follower := range followers {
929 if follower != learnerStore {
930 voterFollowers = append(voterFollowers, follower)
Empty slice literal of type "[][]uint64" used to define "testCases"
903 // disconnect any three stores and change rule to 3 replicas
904 // and there is a learner in the disconnected store.
905 stores := []uint64{1, 2, 3, 4, 5, 6}
906 testCases := [][]uint64{} 907 for i := 0; i < len(stores); i++ {
908 for j := i + 1; j < len(stores); j++ {
909 for k := j + 1; k < len(stores); k++ {
Empty slice literal of type "[][]uint64" used to define "testCases"
811func (suite *ruleCheckerTestSuite) TestFixOrphanPeerWithDisconnectedStoreAndRuleChanged() {
812 // disconnect any two stores and change rule to 3 replicas
813 stores := []uint64{1, 2, 3, 4, 5}
814 testCases := [][]uint64{} 815 for i := 0; i < len(stores); i++ {
816 for j := i + 1; j < len(stores); j++ {
817 testCases = append(testCases, []uint64{stores[i], stores[j]})
Description
An empty slice can be represented by nil
or an empty slice literal. They are
functionally equivalent — their len
and cap
are both zero — but the nil
slice is the preferred style. For more information about empty slices,
see Declaring Empty Slices.
Bad practice
package main
func foo() {
a := []int{}
}
Recommended
package main
func foo() {
var a []int
}