Closed derphilipp closed 4 years ago
TLDR: stored index.html is not found on Windows when delievering via http.FileServer
I packaged an index.html file:
index.html
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
linux/amd64
linux/armv7
darwin/amd64
But when I crosscompile it to windows/amd64...
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.
GOOS
GOARCH
I found out the issue, it had nothing to do with pkger, just a small bug in the build pipeline.
TLDR: stored index.html is not found on Windows when delievering via http.FileServer
I packaged an
index.html
file:And serving it works fine too:
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
andGOARCH
.