Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions loader/loader.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loader

import (
"errors"
"fmt"
"os"
"reflect"
Expand Down Expand Up @@ -82,6 +83,7 @@ func Register[T any](name string, factory func() Builder[T]) {
registryForType.m[name] = factory
}

// Loader is a struct which can dyanmically unmarshal any type T
type Loader[T any] struct {
Builder[T]
}
Expand Down Expand Up @@ -111,6 +113,10 @@ func (b *Loader[T]) UnmarshalJSON(raw []byte) error {
}

func (l Loader[T]) Configure() (T, error) {
var t T
if l.Builder == nil {
return t, errors.New("no type registered for configuration")
}
return l.Builder.Configure()
}

Expand Down