fs: Update comments

This commit is contained in:
Adnan Maolood 2021-01-14 22:24:26 -05:00
parent 06c53cc5b1
commit 8473f3b9d4

13
fs.go
View File

@ -21,6 +21,8 @@ func init() {
// FileServer takes a filesystem and returns a Responder which uses that filesystem. // FileServer takes a filesystem and returns a Responder which uses that filesystem.
// The returned Responder sanitizes paths before handling them. // The returned Responder sanitizes paths before handling them.
//
// TODO: Use io/fs.FS when available.
func FileServer(fsys FS) Responder { func FileServer(fsys FS) Responder {
return fsHandler{fsys} return fsHandler{fsys}
} }
@ -44,12 +46,16 @@ func (fsh fsHandler) Respond(w *ResponseWriter, r *Request) {
_, _ = io.Copy(w, f) _, _ = io.Copy(w, f)
} }
// TODO: replace with io/fs.FS when available // FS represents a filesystem.
//
// TODO: Replace with io/fs.FS when available
type FS interface { type FS interface {
Open(name string) (File, error) Open(name string) (File, error)
} }
// TODO: replace with io/fs.File when available // File represents a file.
//
// TODO: Replace with io/fs.File when available.
type File interface { type File interface {
Stat() (os.FileInfo, error) Stat() (os.FileInfo, error)
Read([]byte) (int, error) Read([]byte) (int, error)
@ -57,6 +63,8 @@ type File interface {
} }
// Dir implements FS using the native filesystem restricted to a specific directory. // Dir implements FS using the native filesystem restricted to a specific directory.
//
// TODO: replace with os.DirFS when available.
type Dir string type Dir string
// Open tries to open the file with the given name. // Open tries to open the file with the given name.
@ -68,6 +76,7 @@ func (d Dir) Open(name string) (File, error) {
// ServeFile responds to the request with the contents of the named file // ServeFile responds to the request with the contents of the named file
// or directory. // or directory.
//
// TODO: Use io/fs.FS when available. // TODO: Use io/fs.FS when available.
func ServeFile(w *ResponseWriter, fs FS, name string) { func ServeFile(w *ResponseWriter, fs FS, name string) {
f, err := fs.Open(name) f, err := fs.Open(name)