Christian Stewart
Christian Stewart

Reputation: 15519

go:embed filename extension patterns

Using go:embed it's possible to embed files:

package main

import "embed"

//go:embed dir
var MyFs embed.FS

"embed" uses the path.Match call internally.

This doesn't work:

//go:embed dir/*{.js,tsx}

I don't see a way to match by filename extensions, is there any way to?

Upvotes: 3

Views: 693

Answers (1)

srpen
srpen

Reputation: 131

Specify the patterns separately:

//go:embed dir/*.js dir/*.tsx
var MyFs embed.FS

Another option is to include the directory and ensure that the names of the files that you don't want to include start with a _ or ..

//go:embed dir

Upvotes: 3

Related Questions