aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext/fileserver.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ext/fileserver.go')
-rw-r--r--pkg/ext/fileserver.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/pkg/ext/fileserver.go b/pkg/ext/fileserver.go
new file mode 100644
index 0000000..fdea08e
--- /dev/null
+++ b/pkg/ext/fileserver.go
@@ -0,0 +1,18 @@
+package ext
+
+import (
+ "io/fs"
+
+ "github.com/valyala/fasthttp"
+)
+
+type FileSystem interface {
+ Open(name string) (fs.File, error)
+}
+
+func FileServer(rootFS FileSystem, rootPath string) fasthttp.RequestHandler {
+ return func(r *fasthttp.RequestCtx) {
+ path := r.UserValue("filepath").(string)
+ r.SendFile(rootPath + path)
+ }
+}