From d6cf67b3d7747b6274d92e394d75d348060fa5f5 Mon Sep 17 00:00:00 2001 From: Gabriel Arakaki Giovanini Date: Sun, 25 Jun 2023 16:03:36 +0200 Subject: feat: Add static file to output bin Now the final binary has a standalone web server including necessary static file. --- pkg/ext/fileserver.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 pkg/ext/fileserver.go (limited to 'pkg/ext') 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) + } +} -- cgit v1.2.3