-
Couldn't load subscription status.
- Fork 24
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Hi,
I'm working on a similar project, but for OneDrive.
The thing that kinda bothers me, is a lack of context.Context support.
I see you resort to context.Background().
The solution I settled on, without violating fs.Fs interface is:
// ContextFS is the interface implemented by a file system that is aware of context.
type ContextFS interface {
fs.FS
// Context returns a new FS with the given context. If the fs.FS implements
// additional interfaces, such as [ReadFileFS], they must be implemented by the
// returned FS.
Context(context.Context) fs.FS
}
For work with multiple fs.ContextFS implementation, one can use this helper:
func FSWithContext[T ContextFS](ctx context.Context, fs T) T {
return fs.Context(ctx).(T)
}
WDYT?
Then you can set context.Context before any fs.Fs use:
f, _ := fs.Context(ctx).Open("extractor_test/foo.json")
defer f.Close()
fileStat, err := fs.Stat(fileSystem.Context(ctx), filePath)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request