Description
In July, @bradfitz and I posted a draft design for embedded files. The doc links to a video, prototype code, and a Reddit discussion.
The feedback on that design has been overwhelmingly positive.
I propose to adopt the embedded files draft design for Go 1.16, with one addition, suggested in the discussion, to simplify the case of direct access to the bytes in a single embedded file.
As long as a file imports "embed"
(import _ "embed"
if necessary), it will be permitted to use //go:embed
naming a single file (no glob patterns or directory matching allowed) to initialize a plain string
or []byte
variable:
//go:embed gopher.png
var gopherPNG []byte
The import is required to flag the file as containing //go:embed
lines and needing processing. Goimports (and gopls etc) can be taught this rule and automatically add the import in any file with a //go:embed
as needed.
The embedded files design depends on the file system interface draft design, which I've also proposed to adopt in #41190.
This issue is only about adopting the embedded files design, under the assumption that the file system interface design is also adopted. If this proposal is accepted before the file system interface design is, we'd simply wait for the file system interface design before starting to land changes.