Prefer nil empty slices

Signed-off-by: David Gageot <david.gageot@docker.com>
This commit is contained in:
David Gageot 2022-10-07 20:40:04 +02:00
parent ebb5ded10b
commit 810c3e788f
No known key found for this signature in database
GPG Key ID: 93C3F22BE5D3A40B
4 changed files with 6 additions and 6 deletions

View File

@ -80,7 +80,7 @@ func mkdir(path string, perm os.FileMode) {
// list of all enabled cgroups
func cgroupList() []string {
list := []string{}
var list []string
f, err := os.Open("/proc/cgroups")
if err != nil {
log.Printf("cannot open /proc/cgroups: %v", err)
@ -125,7 +125,7 @@ func read(path string) string {
// read a directory
func readdir(path string) []string {
names := []string{}
var names []string
files, err := os.ReadDir(path)
if err != nil {
log.Printf("cannot read directory %s: %v", path, err)

View File

@ -85,7 +85,7 @@ func systemInitCmd(ctx context.Context, args []string) {
_ = os.Remove(*sock)
// look for containerd options
ctrdArgs := []string{}
var ctrdArgs []string
var (
stderr io.Writer = os.Stderr
stdout io.Writer = os.Stdout

View File

@ -48,7 +48,7 @@ func ListCDROMs() []Provider {
cdroms = append(cidevs, cdroms...)
cdroms = uniqueString(cdroms)
log.Debugf("unique devices to be checked: %v", cdroms)
providers := []Provider{}
var providers []Provider
for _, device := range cdroms {
providers = append(providers, NewCDROM(device))
}
@ -65,7 +65,7 @@ func FindCIs() []string {
// Glob can only error on invalid pattern
panic(fmt.Sprintf("Invalid glob pattern: %s", blockDevs))
}
foundDevices := []string{}
var foundDevices []string
for _, device := range devs {
// get the base device name
dev := filepath.Base(device)

View File

@ -197,7 +197,7 @@ func makeDevLinks() error {
// return a list of all available drives
func findDrives() []string {
driveKeys := []string{}
var driveKeys []string
ignoreExp := regexp.MustCompile(`^loop.*$|^nbd.*$|^[a-z]+[0-9]+$`)
devs, _ := ioutil.ReadDir("/dev")
for _, d := range devs {