Go1.16 新特性:一文快速上手 Go embed
, _ := f.ReadFile("helloworld/hello2.txt") fmt.Println(string(data2)) } 同时既然能够支持目录读取,也能支持贪婪模式的匹配: //go:embed helloworld/* var f embed.FS 可能会有小伙伴注意到,embed.FS 也能调各类文件系统的接口,其实本质是 embed.FS 实现了 io/fs 接口。 只读属性 在 embed 所提供的 FS 中,我们可以发现其都是打开和只读方法: type FS func (f FS) Open(name string) (fs.File, error) func (f FS) ReadDir(name string) ([]fs.DirEntry, error) func (f FS...阅读全文