Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return concrete *os.FS from Sub() and Subvolume() #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

antoineco
Copy link

First of all thanks for sharing this great project!

While switching between mem.FS and os.FS for different use cases, I noticed that the value returned by (*os.FS).Sub() could not be passed verbatim to receivers that accept an interface such as hpfs.RemoveFS. This is because both Sub() and Subvolume() return a generic hpfs.FS interface instead of the concrete *os.FS type.

It is a common practice in Go to "accept interfaces, return concrete types" and, since there is no ambiguity here, I believe that returning the concrete *os.FS is the right thing to do. It avoids awkward assertions such as:

fs := os.NewFS()
fsi, err := fs.Sub(webroot)
if err != nil { /* ... */ }
fs = fsi.(*os.FS)

myfunc(fs)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant