-
Notifications
You must be signed in to change notification settings - Fork 120
Open
Description
Adding a loader can result in i/o such as network to fetch the referenced schemas. Because of this they should be cancelable via a context.
I suggest that the URLLoader
take a ctx
. As a result a Compiler.Compile()
call should take a context as well.
This would be a breaking change and could wait until a v7 release and/or the existing release could be updated with Context aware methods.
A proposal support in v6:
func (Compiler) CompileContext(ctx context.Context, loc string) (*Schema, error)
// MustCompile omitted as it seems less useful with a context
func (Compiler) RegisterLoaderContext(loader URLLoaderContext)
type URLLoaderContext interface {
// This could also still just be Load(). there shouldn't be a use case to support both Load and LoadContext.
LoadContext(ctx context.Context, url [string](https://pkg.go.dev/builtin#string)) ([any](https://pkg.go.dev/builtin#any), [error](https://pkg.go.dev/builtin#error))
}
```
Internally the `defaultLoader` would always use the context version. `RegisterLoader()` would just then wrap a URLoader with one that adds a default context.Background() by default
simukti, SVilgelm, BattleRattle, artemnesterenko and dschep
Metadata
Metadata
Assignees
Labels
No labels