Skip to content

Commit 22e93e7

Browse files
authored
Merge pull request #13 from runreveal/alan/loader-changes
Sanity Validation Check
2 parents 83009c2 + dd8c826 commit 22e93e7

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

loader/loader.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package loader
22

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"reflect"
@@ -82,6 +83,7 @@ func Register[T any](name string, factory func() Builder[T]) {
8283
registryForType.m[name] = factory
8384
}
8485

86+
// Loader is a struct which can dyanmically unmarshal any type T
8587
type Loader[T any] struct {
8688
Builder[T]
8789
}
@@ -111,6 +113,10 @@ func (b *Loader[T]) UnmarshalJSON(raw []byte) error {
111113
}
112114

113115
func (l Loader[T]) Configure() (T, error) {
116+
var t T
117+
if l.Builder == nil {
118+
return t, errors.New("no type registered for configuration")
119+
}
114120
return l.Builder.Configure()
115121
}
116122

0 commit comments

Comments
 (0)