Skip to content

proposal: embed: //go:embed directive to embed current file if no argument given #58130

@sding3

Description

@sding3

For a variable located in foo.go to embed the file foo.go, we need:

//go:embed foo.go
var file string

It would be convenient if the embed directive interprets the empty argument as to embed the current source file, e.g.:

//go:embed
var file string

I was looking to do documentation generation by parsing out godoc comment of a go source file that contains many configuration parameters for a program by embedding that file and parsing the AST. By allowing the embed directive embed the source file that the directive appears in when no arguments are given, I no longer have to couple the embed directive argument with that source file's filename (i.e., no longer need to update the embed directive every time the source code's filename is changed).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions