4 ms·
An 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 pa
by yiyus 6y ago
An 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