diff options
Diffstat (limited to 'pkg/ext/fileserver.go')
-rw-r--r-- | pkg/ext/fileserver.go | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/pkg/ext/fileserver.go b/pkg/ext/fileserver.go deleted file mode 100644 index 87c1ae8..0000000 --- a/pkg/ext/fileserver.go +++ /dev/null @@ -1,33 +0,0 @@ -package ext - -import ( - "io/fs" - "mime" - "path/filepath" - - "github.com/valyala/fasthttp" -) - -type FileSystem interface { - Open(name string) (fs.File, error) -} - -// This is a VERY simple file server. It does not take a lot into consideration -// and it should only be used to return small predictable files, like in the -// static folder. -func FileServer(rootFS FileSystem) fasthttp.RequestHandler { - return func(ctx *fasthttp.RequestCtx) { - path := ctx.UserValue("filepath").(string) - - f, err := rootFS.Open(path) - if err != nil { - InternalServerError(ctx, err) - return - } - defer f.Close() - - m := mime.TypeByExtension(filepath.Ext(path)) - ctx.SetContentType(m) - ctx.SetBodyStream(f, -1) - } -} |