Hacker News new | past | comments | ask | show | jobs | submit login

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).



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




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: