hackpadfs
hackpadfs copied to clipboard
Return concrete *os.FS from Sub() and Subvolume()
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)