Empty slice literal of type "[]uint64" used to define "voterFollowers"
921 if learnerStore == leader {
922 continue
923 }
924 voterFollowers := []uint64{} 925 for _, follower := range followers {
926 if follower != learnerStore {
927 voterFollowers = append(voterFollowers, follower)
Empty slice literal of type "[][]uint64" used to define "testCases"
900 // disconnect any three stores and change rule to 3 replicas
901 // and there is a learner in the disconnected store.
902 stores := []uint64{1, 2, 3, 4, 5, 6}
903 testCases := [][]uint64{} 904 for i := 0; i < len(stores); i++ {
905 for j := i + 1; j < len(stores); j++ {
906 for k := j + 1; k < len(stores); k++ {
Empty slice literal of type "[][]uint64" used to define "testCases"
808func (suite *ruleCheckerTestSuite) TestFixOrphanPeerWithDisconnectedStoreAndRuleChanged() {
809 // disconnect any two stores and change rule to 3 replicas
810 stores := []uint64{1, 2, 3, 4, 5}
811 testCases := [][]uint64{} 812 for i := 0; i < len(stores); i++ {
813 for j := i + 1; j < len(stores); j++ {
814 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
}