1 // Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2 // Use of this source code is governed by a MIT style
3 // license that can be found in the LICENSE file.
12 type onlyfilesFS struct {
16 type neuteredReaddirFile struct {
20 // Dir returns a http.Filesystem that can be used by http.FileServer(). It is used internally
21 // in router.Static().
22 // if listDirectory == true, then it works the same as http.Dir() otherwise it returns
23 // a filesystem that prevents http.FileServer() to list the directory files.
24 func Dir(root string, listDirectory bool) http.FileSystem {
29 return &onlyfilesFS{fs}
32 // Open conforms to http.Filesystem.
33 func (fs onlyfilesFS) Open(name string) (http.File, error) {
34 f, err := fs.fs.Open(name)
38 return neuteredReaddirFile{f}, nil
41 // Readdir overrides the http.File default implementation.
42 func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
43 // this disables directory listing