Skip to content

proposal: embed: treat / as module's root in go:embed directive #58525

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

Closed
gucio321 opened this issue Feb 14, 2023 · 7 comments
Closed

proposal: embed: treat / as module's root in go:embed directive #58525

gucio321 opened this issue Feb 14, 2023 · 7 comments

Comments

@gucio321
Copy link
Contributor

Consider the following code:

//go:embed /example/path
var data embed.FS

f, err := data.Open("example/path/file.txt")

Since fs.ValidPath, sadly Open will not be able to handle this / at the beginning, but it could be treated as module's root (in go:embed directive) and than removed from embed.FS.

@gopherbot gopherbot added this to the Proposal milestone Feb 14, 2023
@00z20

This comment was marked as spam.

@seankhliao
Copy link
Member

what would this resolve to in non module mode?

@gucio321
Copy link
Contributor Author

thre would be two options imao:

  1. as the most common use-case of non-module programms is "scripting", the root dir same as script's root, so equal to .
  2. disable this pattern in non-module mode

@rsc
Copy link
Contributor

rsc commented Mar 15, 2023

In general source files are not supposed to depend on where module boundaries are. We want to be able to split a module into two modules without having to go edit every single file in the module. The special meaning for "/" would break that property. It also complicates interpretation by other tools. It would also introduce ambiguity in that

//go:build /foo foo

would have two different foo being embedded, both laying claim to data.Open("foo").

The current limitation of embedded files being required to be in the current package directory or a subdirectory seems acceptable given the complexities we'd be introducing to try to remove it.

@rsc
Copy link
Contributor

rsc commented Mar 29, 2023

This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group

@rsc rsc moved this from Incoming to Active in Proposals Mar 29, 2023
@rsc
Copy link
Contributor

rsc commented Apr 6, 2023

Based on the discussion above, this proposal seems like a likely decline.
— rsc for the proposal review group

@rsc rsc moved this from Active to Likely Decline in Proposals Apr 6, 2023
@rsc rsc moved this from Likely Decline to Declined in Proposals Apr 12, 2023
@rsc
Copy link
Contributor

rsc commented Apr 12, 2023

No change in consensus, so declined.
— rsc for the proposal review group

@rsc rsc closed this as completed Apr 12, 2023
@golang golang locked and limited conversation to collaborators Apr 11, 2024
@rsc rsc removed this from Proposals Apr 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants