Merge mssql and dfsr expandEnabledCollectors func

Move to common collector.go and add function test.

Signed-off-by: Ben Reedy <breed808@breed808.com>
This commit is contained in:
Ben Reedy
2020-12-03 20:20:28 +10:00
parent ccac306c2d
commit b5ce53fdac
4 changed files with 57 additions and 35 deletions

View File

@@ -2,6 +2,7 @@ package collector
import (
"fmt"
"sort"
"strconv"
"strings"
@@ -128,3 +129,22 @@ func find(slice []string, val string) bool {
}
return false
}
// Used by more complex collectors where user input specifies enabled child collectors.
// Splits provided child collectors and deduplicate.
func expandEnabledChildCollectors(enabled string) []string {
separated := strings.Split(enabled, ",")
unique := map[string]bool{}
for _, s := range separated {
if s != "" {
unique[s] = true
}
}
result := make([]string, 0, len(unique))
for s := range unique {
result = append(result, s)
}
// Ensure result is ordered, to prevent test failure
sort.Strings(result)
return result
}