From 6124d3dfd274ac24e5da0817ae172aca58c22d4e Mon Sep 17 00:00:00 2001 From: Dave Henderson Date: Thu, 3 May 2018 21:50:37 -0400 Subject: Adding datasourceReachable function Signed-off-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 e4336fb5..6370bd5f 100644 --- a/data/datasource.go +++ b/data/datasource.go @@ -257,6 +257,17 @@ func (d *Data) Datasource(alias string, args ...string) (interface{}, error) { return nil, errors.Errorf("Datasources of type %s not yet supported", source.Type) } +// DatasourceReachable - Determines if the named datasource is reachable with +// the given arguments. Reads from the datasource, and discards the returned data. +func (d *Data) DatasourceReachable(alias string, args ...string) bool { + source, ok := d.Sources[alias] + if !ok { + return false + } + _, err := d.ReadSource(source, args...) + return err == nil +} + // Include - func (d *Data) Include(alias string, args ...string) (string, error) { source, ok := d.Sources[alias] -- cgit v1.2.3