Skip to content

Commit daca615

Browse files
committed
return a typed data source using generics
Signed-off-by: Etai Lev Ran <[email protected]>
1 parent d687ae6 commit daca615

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/epp/datalayer/datasource.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,27 @@ func (dsr *DataSourceRegistry) GetSources() []DataSource {
9292

9393
// --- default registry accessors ---
9494

95+
// RegisterSource adds a new data source to the default registry.
9596
func RegisterSource(src DataSource) error {
9697
return defaultDataSources.Register(src)
9798
}
9899

99-
func GetNamedSource(name string) (DataSource, bool) {
100-
return defaultDataSources.GetNamedSource(name)
100+
// GetNamedSourceTyped returns a typed data source from the default registry.
101+
func GetNamedSource[T DataSource](name string) (T, bool) {
102+
v, ok := defaultDataSources.GetNamedSource(name)
103+
if !ok {
104+
var zero T
105+
return zero, false
106+
}
107+
src, ok := v.(T)
108+
if !ok {
109+
var zero T
110+
return zero, false
111+
}
112+
return src, true
101113
}
102114

115+
// GetSources returns the list of data sources registered in the default registry.
103116
func GetSources() []DataSource {
104117
return defaultDataSources.GetSources()
105118
}

0 commit comments

Comments
 (0)