From 112083a9cd19d639f9eaeccd74d6e301f43fb24d Mon Sep 17 00:00:00 2001 From: John Wang Date: Sat, 28 Oct 2023 10:18:58 -0700 Subject: [PATCH] feat: `database/datasource`: add `DataSourceSet{}` --- database/datasource/datasource_set.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 database/datasource/datasource_set.go diff --git a/database/datasource/datasource_set.go b/database/datasource/datasource_set.go new file mode 100644 index 00000000..920892d6 --- /dev/null +++ b/database/datasource/datasource_set.go @@ -0,0 +1,22 @@ +package datasource + +import ( + "fmt" + + "github.com/grokify/mogo/type/maputil" +) + +type DataSourceSet struct { + Data map[string]DataSource +} + +func (dss DataSourceSet) GetDataSource(key string) (DataSource, error) { + if ds, ok := dss.Data[key]; ok { + return ds, nil + } + return DataSource{}, fmt.Errorf("key not found (%s)", key) +} + +func (dss DataSourceSet) Keys() []string { + return maputil.Keys(dss.Data) +}