Skip to content

Commit

Permalink
adding strip prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
syntaqx committed Jan 15, 2019
1 parent 35af3d8 commit 1b332f3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ import "net/http"

// Options is a struct for specifying configuration options for a FileServer.
type Options struct {
// Directory is the root directory from which to serve files.
Directory string

// Prefix is a filepath prefix that should be ignored by the FileServer.
Prefix string
}

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

fs.handler = http.FileServer(http.Dir(opt.Directory))
fs.handler = http.StripPrefix(opt.Prefix, http.FileServer(http.Dir(opt.Directory)))
return fs
}

Expand Down

0 comments on commit 1b332f3

Please sign in to comment.