| 1 | // +build go1.16 |
| 2 | |
| 3 | package render |
| 4 | |
| 5 | import ( |
| 6 | "embed" |
| 7 | "io/fs" |
| 8 | "path/filepath" |
| 9 | ) |
| 10 | |
| 11 | // EmbedFileSystem implements FileSystem on top of an embed.FS |
| 12 | type EmbedFileSystem struct { |
| 13 | embed.FS |
| 14 | } |
| 15 | |
| 16 | var _ FileSystem = &EmbedFileSystem{} |
| 17 | |
| 18 | func (e *EmbedFileSystem) Walk(root string, walkFn filepath.WalkFunc) error { |
| 19 | return fs.WalkDir(e.FS, root, func(path string, d fs.DirEntry, _ error) error { |
| 20 | if d == nil { |
| 21 | return nil |
| 22 | } |
| 23 | |
| 24 | info, err := d.Info() |
| 25 | if err != nil { |
| 26 | return err |
| 27 | } |
| 28 | |
| 29 | return walkFn(path, info, err) |
| 30 | }) |
| 31 | } |