Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

go:embed filename extension patterns

Tags:

go

embed

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?

like image 421
Christian Stewart Avatar asked Sep 15 '26 13:09

Christian Stewart


1 Answers

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
like image 106
srpen Avatar answered Sep 17 '26 02:09

srpen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!