Skip to content

Commit 27adeba

Browse files
authored
Merge pull request #1065 from elezar/skip-nill-discoverers
Skip nil discoverers in merge
2 parents 132c9af + 0c765c6 commit 27adeba

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

internal/discover/list.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,28 @@ import "fmt"
2121
// list is a discoverer that contains a list of Discoverers. The output of the
2222
// Mounts functions is the concatenation of the output for each of the
2323
// elements in the list.
24-
type list struct {
25-
discoverers []Discover
26-
}
24+
type list []Discover
2725

2826
var _ Discover = (*list)(nil)
2927

3028
// Merge creates a discoverer that is the composite of a list of discoverers.
31-
func Merge(d ...Discover) Discover {
32-
l := list{
33-
discoverers: d,
29+
func Merge(discoverers ...Discover) Discover {
30+
var l list
31+
for _, d := range discoverers {
32+
if d == nil {
33+
continue
34+
}
35+
l = append(l, d)
3436
}
3537

36-
return &l
38+
return l
3739
}
3840

3941
// Devices returns all devices from the included discoverers
4042
func (d list) Devices() ([]Device, error) {
4143
var allDevices []Device
4244

43-
for i, di := range d.discoverers {
45+
for i, di := range d {
4446
devices, err := di.Devices()
4547
if err != nil {
4648
return nil, fmt.Errorf("error discovering devices for discoverer %v: %v", i, err)
@@ -55,7 +57,7 @@ func (d list) Devices() ([]Device, error) {
5557
func (d list) Mounts() ([]Mount, error) {
5658
var allMounts []Mount
5759

58-
for i, di := range d.discoverers {
60+
for i, di := range d {
5961
mounts, err := di.Mounts()
6062
if err != nil {
6163
return nil, fmt.Errorf("error discovering mounts for discoverer %v: %v", i, err)
@@ -70,7 +72,7 @@ func (d list) Mounts() ([]Mount, error) {
7072
func (d list) Hooks() ([]Hook, error) {
7173
var allHooks []Hook
7274

73-
for i, di := range d.discoverers {
75+
for i, di := range d {
7476
hooks, err := di.Hooks()
7577
if err != nil {
7678
return nil, fmt.Errorf("error discovering hooks for discoverer %v: %v", i, err)

0 commit comments

Comments
 (0)