-
Notifications
You must be signed in to change notification settings - Fork 83
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Path mismatch when using dev
tag
#77
Comments
I'm curious about this as well. There are a few other folks who have put together examples of vfsgen's usage (https://github.com/ahrtr/vfsgenDemo and https://github.com/artificerpi/vfsgen-sample), but they all seem to have the same issue: they place assets in a subdirectory of a subpackage, but use a path relative to the root of the subpackage in their I'm not certain either of these samples have been tested in development mode 😄 |
Sorry I missed this earlier. Your definition of When I suggest fixing this problem by defining func importPathToDir(importPath string) string {
p, err := build.Import(importPath, "", build.FindOnly)
if err != nil {
log.Fatalln(err)
}
return p.Dir
} Then you can do something like: var Assets http.FileSystem = http.Dir(filepath.Join(importPathToDir("github.com/gargath/vfstest"), "frontend")) You can see an example of me using |
This is excellent. Thanks! |
I literally just started using vfsgen (30min ago) and bumped into this immediately, no idea how so many projects use relative paths, pretty sure they have never executed with I decided to go with a
And defining http.Dir to just When executing But even though I agree that relative paths are prone to errors, maybe the helper mentioned in this issue should be part of the package officially? |
I'm trying to follow the example in the README on how to handle local filesystem vs embedded assets with a
dev
build tag.My project looks like this:
In my
data.go
I have:while in
dev.go
I have:My
cmd/main.go
is a simpleWhen I run
go generate ./pkg/...
and thengo build -o vfserver github.com/gargath/vfstest/cmd
, I get a working binary that serves the embedded content.However, when running
go build -tags dev -o vfserver github.com/gargath/vfstest/cmd
, I get 404 errors from the HTTP server because it is now trying to find the path../../frontend/
relative to the binary in the project root.I can fix this by changing the path in
data.Assets
tofrontend/
, but thengo generate
no longer works:How can I structure a project so that the same static assets directory can be used to both generate and serve locally?
The text was updated successfully, but these errors were encountered: