markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)
MIT License
1.18k stars 60 forks source link

Serving http.FileServer via pkger.Dir does not work on Windows? #75

Closed derphilipp closed 4 years ago

derphilipp commented 4 years ago

TLDR: stored index.html is not found on Windows when delievering via http.FileServer

I packaged an index.html file:

pkger list 

github.com/derphilipp/foo
 > github.com/derphilipp/foo:/html
 > github.com/derphilipp/foo:/html/index.html

And serving it works fine too:

 func startPackrWebserver() {
     logrus.Info("Serving website files from packr")

     fs := http.FileServer(pkger.Dir("/html"))
     http.Handle("/", fs)
 }

This works for linux/amd64, linux/armv7, darwin/amd64

But when I crosscompile it to windows/amd64...

GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-extldflags '-static' -X github.com/derphilipp/foo/version.Version=${VERSION} -X github.com/derphilipp/foo/version.GitCommit=${GIT_COMMIT}${GIT_DIRTY} -X github.com/derphilipp/foo/version.BuildDate=${BUILD_DATE}" -o bin/windows-amd64

...the resulting binary start the webserver but always delievers a 404 error - it seems it cannot find the index.html

The build settings are used for all the other builds too and only differ in GOOS and GOARCH.

derphilipp commented 4 years ago

I found out the issue, it had nothing to do with pkger, just a small bug in the build pipeline.