From 1b332f32ce2f5296db578abbf249f94563c89c95 Mon Sep 17 00:00:00 2001 From: Chase Hutchins Date: Tue, 15 Jan 2019 01:14:01 -0700 Subject: [PATCH] adding strip prefix --- serve.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/serve.go b/serve.go index fd175ca..25e52af 100644 --- a/serve.go +++ b/serve.go @@ -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. @@ -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 }