go:embed filename extension patterns 翻译结果: go:embed 文件名扩展模式

huangapple go评论72阅读模式
英文:

go:embed filename extension patterns

问题

使用go:embed可以嵌入文件:

package main

import "embed"

//go:embed dir
var MyFs embed.FS

"embed"在内部使用path.Match调用。

这种方式不起作用:

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

我没有看到通过文件名扩展名进行匹配的方法,有没有任何方法可以实现?

英文:

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?

答案1

得分: 2

将模式分别指定如下:

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

另一种选项是包含目录,并确保不想包含的文件名以 _. 开头。

//go:embed dir
英文:

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

huangapple
  • 本文由 发表于 2022年10月3日 08:44:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/73930239.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定