Replies: 3 comments 1 reply
-
Great suggestions! So for adding context to each method signature, are you saying that it'd look something like this in the deprecation phase? v7 - add Context version of method // Deprecated: old function
func (*File) Write([]byte) error {
f.Write(context.Background(), []bytes))
}
// WriteWithContext - use me instead
func (*File) WriteWithContext(ctx, []byte) error { ... } v8 - rename back to Write() // Write - use me instead
func (*File) Write(ctx, []byte) error { ... } |
Beta Was this translation helpful? Give feedback.
-
Altering Read or Write is actually a bad idea since it would break the implementation of the io.* interfaces :( |
Beta Was this translation helpful? Give feedback.
-
In the last several years, google released readonly filesystem interface in package |
Beta Was this translation helpful? Give feedback.
-
Proposed changes to vfs in next major release
This is meant to be a starting point for discussion, not a final draft. Nothing int his discussion should be thought of as set in stone. Indeed, much of what is initially added will need to be fleshed out further.
Improve Standardization between backends
Create new behavior-driven test suite
Currently each backend implementation have mostly the same behavior but because a rickety and incomplete test suite, it's impossible to ensure compliance. There are some subtle differences with authority behavior that needs to be worked in the test suite. For instance,
os
andmem
allow for empty authority (volume) while the reset do not.Proposed
Standardize Errors
To help facilitate the proposed test suite, we should be using standard errors that can be universally checked using Go 1.13+ errors functions (Is, As, Unwrap). I really like Dave Cheney's thoughts on this https://dave.cheney.net/tag/error-handling about creating immutable but most importantly fungible errors.
Proposed
fmt.Errorf("%w")
error wrapping when error decoration is desiredBreaking Changes
Deprecate Volume and ChangeDir terminology and functions
Initial development of
vfs
tried to constrain functionality to what we could accomplish in all filesystems we could think of (ie., unix os, windows os [we are dismally broken in windows], AWS S3, Google Storage, Azure Blob storage, SFTP, etc). We decided that when default behaviors between filesystems conflicted, we'd choose theos
behavior as pattern we'd most closely follow. Along with this, we borrowed some terminology fromos
that may not apply everywhere, includingFile
,Volume
,ChangeDir
. However, as it turns out, that while our use of URI as the means for resource locating has worked extremely well, the termsVolume
andChangeDir
are not universally applicable.Volume
In the pattern above, for
sftp
(andftp
) authority is user + host + port. Fors3
andgs
the authority is a bucket. Formem
, namespaces are the optional authority. For os (mainly for windows, unix doesn't distinguish between volumes and directories), it is optionally a volume or mount. Azure is complicated because of its hostname and its container concept and its URI pattern we might revisit but will remain out-of-scope for this proposal.ChangDir
ChangeDir(relLocPath) is the only place we actually use the term "Dir" (vs Location). It updates the existing Location's path to the provided relative location path. As far as I can see, its behavior is redundant.
We can accomplish the same thing by doing:
I can't see a valid reason for keeping this in the Location interface. Smaller interface = better interface.
Proposed:
Support context.Context
Most network-based backends' underlying API's support
context
butvfs
does not. We should add context to support to our interface, providing timeout and cancellation. This would largely entail adding a ctx to the front of most arg lists.Proposed:
Redesign Options
We currently pass options an empty interface called
vfs.Options
and then cast it as implementation-specific stuct like s3.Options, applying globally.We should consider using variadic functional options instead (https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis) and apply them in various contexts. In other words, we could have Filesystem-level options, Location-level options, and File-level.
Here we've set some global option including authentications, logging, retry, at-rest encryption, and file permissions defaults. However, when setting up
newfile
we decide to override the global settings a different set of permissions.Note that
existingFile
didn't have to pass any options because the variadic signature allowed for passing nothing. So it will just use any relevant global settings.Proposed
Redesign List functions
TBD
Beta Was this translation helpful? Give feedback.
All reactions