linux: more idiomatic array operations on GetPortLists
This commit is contained in:
@@ -60,8 +60,7 @@ func GetPortsList() ([]string, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ports := make([]string, len(files))
|
ports := make([]string, 0, len(files))
|
||||||
found := 0
|
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
// Skip folders
|
// Skip folders
|
||||||
if f.IsDir() {
|
if f.IsDir() {
|
||||||
@@ -92,12 +91,10 @@ func GetPortsList() ([]string, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save found serial port in the resulting list
|
// Save serial port in the resulting list
|
||||||
ports[found] = portName
|
ports = append(ports, portName)
|
||||||
found++
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ports = ports[:found]
|
|
||||||
return ports, nil
|
return ports, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user