Better NFS
This commit is contained in:
parent
2c3f84d527
commit
d00e356bc2
@ -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
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
type neuteredReaddirFile struct {
|
||||
http.File
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
|
||||
return nil, nil
|
||||
return f, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user