4 ms·
Yeah! (as long as the UI/UX folks don't mind a bit of Go code in their repo) I was kind of hoping for: package foo //go:embed $ASSETS/* var assets embe
by lsllc 6y ago
Yeah! (as long as the UI/UX folks don't mind a bit of Go code in their repo)
I was kind of hoping for:
package foo
//go:embed $ASSETS/*
var assets embed.Files
But one issue with this is that it might make a dogs breakfast of the filenames within the `assets` object -- it sort of needs something like this:
//go:embed * from $ASSETS
(and it would not include the $ASSETS path in the object).
- yiyus 6y agoAn interesting option that I've not seen proposed yet would be to accept go:embed comments before importing a package (obviating the need to write the assets package in my previous example). So, assuming your assets are in the repository github.com/me/myproject/assets, you could just do: package foo //go:embed */* import "github.com/me/myproject/assets" And the go tool would take charge of generating an assets package with assets.Files. Then we don't even need a magic embed package at all. And generating a package would give us more flexibility, for example: package foo // import "foo.io/foo" //go:embed Name string "name.txt" //go:embed Data []byte "bin.dat" //go:embed "images" "templates" "html/index.html" import embedded "foo.io/foo" //use embedded.Name, with type string //use embedded.Data, with type []byte //use embedded.Files, with type fs.FS