From 0ca223237a0714eebe4e8f3da10e09031999537f Mon Sep 17 00:00:00 2001 From: jeevansai Date: Sat, 5 Feb 2022 19:52:00 +0530 Subject: Add function to list datasources (#1287) * Add function to list datasources * Sort datasources in ascending order and return in listDatasources * Fix lint error Signed-off-by: Dave Henderson Co-authored-by: Dave Henderson --- data/datasource.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'data/datasource.go') diff --git a/data/datasource.go b/data/datasource.go index 5f684a4c..79c29e5f 100644 --- a/data/datasource.go +++ b/data/datasource.go @@ -7,6 +7,7 @@ import ( "net/http" "net/url" "path/filepath" + "sort" "strings" "github.com/spf13/afero" @@ -382,3 +383,13 @@ func (d *Data) readSource(ctx context.Context, source *Source, args ...string) ( d.cache[cacheKey] = data return data, nil } + +// Show all datasources - +func (d *Data) ListDatasources() []string { + datasources := make([]string, 0, len(d.Sources)) + for source := range d.Sources { + datasources = append(datasources, source) + } + sort.Strings(datasources) + return datasources +} -- cgit v1.2.3