1
0
Fork 0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-05-18 20:36:04 +02:00

fs: Update documentation

This commit is contained in:
Adnan Maolood 2021-02-14 19:27:56 -05:00
parent 46e10da3a8
commit 5ec8dea1ba

14
fs.go
View File

@ -14,10 +14,8 @@ func init() {
}
// FileServer returns a handler that serves Gemini requests with the contents
// of the file system rooted at root.
// of the provided file system.
// The returned handler cleans paths before handling them.
//
// TODO: Use io/fs.FS when available.
func FileServer(fsys FS) Handler {
return fsHandler{fsys}
}
@ -41,16 +39,12 @@ func (fsh fsHandler) ServeGemini(w ResponseWriter, r *Request) {
_, _ = io.Copy(w, f)
}
// FS represents a filesystem.
//
// TODO: Replace with io/fs.FS when available.
// FS represents a file system.
type FS interface {
Open(name string) (File, error)
}
// File represents a file.
//
// TODO: Replace with io/fs.File when available.
type File interface {
Stat() (os.FileInfo, error)
Read([]byte) (int, error)
@ -58,8 +52,6 @@ type File interface {
}
// Dir implements FS using the native filesystem restricted to a specific directory.
//
// TODO: replace with os.DirFS when available.
type Dir string
// Open tries to open the file with the given name.
@ -71,8 +63,6 @@ func (d Dir) Open(name string) (File, error) {
// ServeFile responds to the request with the contents of the named file
// or directory.
//
// TODO: Use io/fs.FS when available.
func ServeFile(w ResponseWriter, fs FS, name string) {
f, err := fs.Open(name)
if err != nil {