/embedfs-web-go

Just an EmbedFS example serving a static webpage

Primary LanguageGoMIT LicenseMIT

embedfs-web-go

Example of running a file server using //go:embed.

Run locally

go run main.go --addr "localhost:8080"

Run as a static binary

go build -o fileserver .
./fileserver --addr "localhost:8080"

Run as a Docker image

Please note socket bind to the virtual ethernet device (0.0.0.0) rather than loopback (localhost):

docker build . -t fileserver
docker run -it --rm -p 8080:8080 --user 65534:65534 \
  fileserver --addr 0.0.0.0:8080

Change the path

To change the path from static, update the path in both the constant variable, and the //go:embed directive:

--- main.go     2024-05-29 19:06:09
+++ main2.go    2024-05-29 19:25:09
@@ -15,9 +15,9 @@
-const path = "static"
+const path = "path/to/dir"

-//go:embed static
+//go:embed path/to/dir