-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
42 lines (31 loc) · 775 Bytes
/
server.go
File metadata and controls
42 lines (31 loc) · 775 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package fileserver
import (
"net/http"
"os"
)
/*
http.Handle("/", http.FileServer(http.Dir("/tmp")))
The original http.FileServer() will show directory listings, this one does not
https://groups.google.com/forum/#!topic/golang-nuts/bStLPdIVM6w
Example:
func main() {
fs := simplefileserver.OnlyFilesFilesystem{http.Dir("/tmp/")}
http.ListenAndServe(":8080", http.FileServer(fs))
}
*/
type OnlyFilesFilesystem struct {
FS http.FileSystem
}
type neuteredReaddirFile struct {
http.File
}
func (fs OnlyFilesFilesystem) Open(name string) (http.File, error) {
f, err := fs.FS.Open(name)
if err != nil {
return nil, err
}
return neuteredReaddirFile{f}, nil
}
func (f neuteredReaddirFile) Readdir(count int) ([]os.FileInfo, error) {
return nil, nil
}