diff --git a/neutered-filesystem.go b/neutered-filesystem.go index 2dd4001..d7e16d9 100644 --- a/neutered-filesystem.go +++ b/neutered-filesystem.go @@ -2,7 +2,7 @@ package neutered_filesystem import ( "net/http" - "os" + "path/filepath" ) type NeuteredFileSystem struct { @@ -13,18 +13,24 @@ func New(fs http.FileSystem) NeuteredFileSystem { return NeuteredFileSystem{fs} } -func (fs NeuteredFileSystem) Open(name string) (http.File, error) { - f, err := fs.fs.Open(name) +func (nfs NeuteredFileSystem) Open(name string) (http.File, error) { + f, err := nfs.fs.Open(name) if err != nil { return nil, err } - return neuteredReaddirFile{f}, nil -} -type neuteredReaddirFile struct { - http.File -} + s, err := f.Stat() + if s.IsDir() { + index := filepath.Join(name, "index.html") + if _, err := nfs.fs.Open(index); err != nil { + closeErr := f.Close() + if closeErr != nil { + return nil, closeErr + } -func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) { - return nil, nil + return nil, err + } + } + + return f, nil }