Skip to content

Commit 1b332f3

Browse files
committed
adding strip prefix
1 parent 35af3d8 commit 1b332f3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

serve.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import "net/http"
55

66
// Options is a struct for specifying configuration options for a FileServer.
77
type Options struct {
8+
// Directory is the root directory from which to serve files.
89
Directory string
10+
11+
// Prefix is a filepath prefix that should be ignored by the FileServer.
12+
Prefix string
913
}
1014

1115
// FileServer wraps an http.FileServer.
@@ -27,7 +31,7 @@ func NewFileServer(options ...Options) *FileServer {
2731
opt: opt,
2832
}
2933

30-
fs.handler = http.FileServer(http.Dir(opt.Directory))
34+
fs.handler = http.StripPrefix(opt.Prefix, http.FileServer(http.Dir(opt.Directory)))
3135
return fs
3236
}
3337

0 commit comments

Comments
 (0)