-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
//go:embed <path to file in parent directory>
doesn't work
#46056
Comments
This is intentional and documnted
|
@seankhliao is it possible to make it a feature request? |
It still can't cross module boundaries, and if it's in the same module you can just put the embed directive in a go file in the parent directory |
yah, this solution is possible, but it would be a bit crazy. |
@seankhliao maybe |
This was an explicit design decision:
ref: https://go.googlesource.com/proposal/+/master/design/draft-embed.md |
To start using the new ✨ [embed pkg](https://pkg.go.dev/embed) and deprecate our use of packr we need to move all of our templates under the `internal/pkg/template` pkg. This is because unfortunately we can't refer to the current "templates" directory by doing `"../../../templates"`: > Because embed.Files implements fs.FS, it cannot provide access to files with names beginning with .., so files in parent directories are also disallowed entirely, even when the parent directory named by .. does happen to be in the same module. > > golang/go#46056 (comment) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
…#2691) To start using the new ✨ [embed pkg](https://pkg.go.dev/embed) and deprecate our use of packr we need to move all of our templates under the `internal/pkg/template` pkg. This is because unfortunately we can't refer to the current "templates" directory by doing `"../../../templates"`: > Because embed.Files implements fs.FS, it cannot provide access to files with names beginning with .., so files in parent directories are also disallowed entirely, even when the parent directory named by .. does happen to be in the same module. > > golang/go#46056 (comment) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
* Removed installing go genesis. * Removed the existing genesis file handler. * Changed to go embed for file serving. * Updated envsetup.sh to generate frontend within assets package. * Had to generate within assets package because go embed does not support path traversing golang/go#46056
* Removed installing go genesis. * Removed the existing genesis file handler. * Changed to go embed for file serving. * Updated envsetup.sh to generate frontend within assets package. * Had to generate within assets package because go embed does not support path traversing golang/go#46056
@gucio321 There is no need to put embed files into child directories, I found this in embed draft. |
There's a major bug with this: I have the COPYING license file in my project root. But my CLI package which wants to display that text is in a subdir. And so I can't |
I agree. It makes sense to limit //go:generate cp -r ../../assets ./local-asset-dir
//go:embed local-asset-dir
var assetFs embed.FS This works but it looks bad and I would like to avoid it. |
@korya , does your solution work to embed one file into a slice of bytes? |
@korya what do you mean by |
hmm, right, it may work, but it will not be portable :-(. |
I have the same issue, |
Wouldn't it be nice if embed could support predefined variables like 'dirname' or 'projectname' to avoid some unexpected bug and thus avoid the '..' or '.'? |
it sounds nice! |
Sounds good to me! |
If it's still relevant I found good answer here. |
We remove the `--schema` flag from the `gen-installer` command, for it's no longer perceived to be useful. We move the tempate file `install.sh.tmpl` to the `files/` directory for consistency. Due to a golang constraint (cf. golang/go#46056), we created a package `files` to make the installer template available to other packages. Thank @alecthomas and @jvmakine for their feedback.
Add hermit gen-installer subcommand. It prints the SHA-256 digest of the generated installer script to stdout. We also perform a cross-check in CI to make sure `cmd/geninstaller` and `hermit gen-installer` produce identical installer scripts. We remove the `--schema` flag from the `gen-installer` command, for it's no longer perceived to be useful. We move the tempate file `install.sh.tmpl` to the `files/` directory for consistency. Due to a golang constraint (cf. golang/go#46056), we created a package `files` to make the installer template available to other packages.
maybe do this,Create a new assets.go in the directory that needs to be packaged
Then use this variable in another package
|
…#2691) To start using the new ✨ [embed pkg](https://pkg.go.dev/embed) and deprecate our use of packr we need to move all of our templates under the `internal/pkg/template` pkg. This is because unfortunately we can't refer to the current "templates" directory by doing `"../../../templates"`: > Because embed.Files implements fs.FS, it cannot provide access to files with names beginning with .., so files in parent directories are also disallowed entirely, even when the parent directory named by .. does happen to be in the same module. > > golang/go#46056 (comment) By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
I want my webpack bundle to go in a different folder than the golang source code. I want to have a |
I think, we needs to "construct" a proposal issue to solve this problem.
In my opinion its not a good justification - it sounds like saying "we can't add this, since it is not implemented"
First of all let me note that putting Any thoughts? |
As mentioned before, not having |
well, but |
The best practice here is to create a package in parent level with |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
There is a following package:
assets.go contains package assets loaded with
//go:embed
directive.I'd like to add
README.md
file to assets.go, but//go:embed ../README.md
doesn't workWhat did you expect to see?
the program should compile and work fine.
What did you see instead?
The text was updated successfully, but these errors were encountered: