...
1
2
3
4
5 package gin
6
7 import (
8 "net/http"
9 "os"
10 )
11
12 type onlyFilesFS struct {
13 fs http.FileSystem
14 }
15
16 type neuteredReaddirFile struct {
17 http.File
18 }
19
20
21
22
23
24 func Dir(root string, listDirectory bool) http.FileSystem {
25 fs := http.Dir(root)
26 if listDirectory {
27 return fs
28 }
29 return &onlyFilesFS{fs}
30 }
31
32
33 func (fs onlyFilesFS) Open(name string) (http.File, error) {
34 f, err := fs.fs.Open(name)
35 if err != nil {
36 return nil, err
37 }
38 return neuteredReaddirFile{f}, nil
39 }
40
41
42 func (f neuteredReaddirFile) Readdir(_ int) ([]os.FileInfo, error) {
43
44 return nil, nil
45 }
46
View as plain text