github.com/rpdict/ponzu@v0.10.1-0.20190226054626-477f29d6bf5e/system/admin/filesystem.go (about) 1 package admin 2 3 import ( 4 "net/http" 5 "os" 6 ) 7 8 func restrict(dir http.Dir) justFilesFilesystem { 9 return justFilesFilesystem{dir} 10 } 11 12 // the code below removes the open directory listing when accessing a URL which 13 // normally would point to a directory. code from golang-nuts mailing list: 14 // https://groups.google.com/d/msg/golang-nuts/bStLPdIVM6w/hidTJgDZpHcJ 15 // credit: Brad Fitzpatrick (c) 2012 16 17 type justFilesFilesystem struct { 18 fs http.FileSystem 19 } 20 21 func (fs justFilesFilesystem) Open(name string) (http.File, error) { 22 f, err := fs.fs.Open(name) 23 if err != nil { 24 return nil, err 25 } 26 return neuteredReaddirFile{f}, nil 27 } 28 29 type neuteredReaddirFile struct { 30 http.File 31 } 32 33 func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) { 34 return nil, nil 35 }