Last active
October 18, 2022 15:18
-
-
Save BrandonClapp/2e47f46b2a0b7d16885abede0ea557c3 to your computer and use it in GitHub Desktop.
Loop over files in an embed FS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"embed" | |
"fmt" | |
"io/fs" | |
) | |
//go:embed template/* | |
var template embed.FS | |
func embedExample() { | |
fs.WalkDir(template, ".", func(path string, d fs.DirEntry, err error) error { | |
if err != nil { | |
return err | |
} | |
// We only care about files | |
if d.IsDir() { | |
return nil | |
} | |
buf, err := fs.ReadFile(template, path) | |
if err != nil { | |
fmt.Println(err.Error()) | |
return err | |
} | |
fmt.Println(string(buf)) | |
// fmt.Printf("path=%q, isDir=%v\n", path, d.IsDir()) | |
return nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment