diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-25 16:03:36 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-06-25 16:12:05 +0200 |
commit | d6cf67b3d7747b6274d92e394d75d348060fa5f5 (patch) | |
tree | 8c48f947e7ab732a38b15eab6a898cb14caa1669 /pkg | |
parent | 57b41ad766b3c4505672c12f058f10c7a132dd5b (diff) | |
download | lens-d6cf67b3d7747b6274d92e394d75d348060fa5f5.tar.gz lens-d6cf67b3d7747b6274d92e394d75d348060fa5f5.tar.bz2 lens-d6cf67b3d7747b6274d92e394d75d348060fa5f5.zip |
feat: Add static file to output bin
Now the final binary has a standalone web server including necessary
static file.
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/ext/fileserver.go | 18 | ||||
-rw-r--r-- | pkg/worker/list_processor_test.go | 3 |
2 files changed, 20 insertions, 1 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) + } +} diff --git a/pkg/worker/list_processor_test.go b/pkg/worker/list_processor_test.go index 35672f3..ce3ff0a 100644 --- a/pkg/worker/list_processor_test.go +++ b/pkg/worker/list_processor_test.go @@ -9,8 +9,9 @@ import ( "sync" "testing" - "git.sr.ht/~gabrielgio/img/pkg/testkit" "github.com/sirupsen/logrus" + + "git.sr.ht/~gabrielgio/img/pkg/testkit" ) type ( |