Skip to content

Instantly share code, notes, and snippets.

@CrimsonK1ng
Created November 15, 2022 02:19
Show Gist options
  • Save CrimsonK1ng/3f42f05c2586fabf83382dd1ba3ecf0e to your computer and use it in GitHub Desktop.
Save CrimsonK1ng/3f42f05c2586fabf83382dd1ba3ecf0e to your computer and use it in GitHub Desktop.
Copy Embed FS To Disk
//go:embed folder/*
var folderEmbed embed.FS
func toDisk() error {
err := fs.WalkDir(folderEmbed, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
err := os.MkdirAll(path, 0755)
if err != nil && !os.IsExist(err) {
log.Fatal(err)
return err
}
return nil
}
newF, err := os.Create(path)
if err != nil {
log.Fatal(err)
return err
}
defer newF.Close()
data, err := folderEmbed.ReadFile(path)
if err != nil {
log.Fatal(err)
return err
}
err = os.WriteFile(path, data, 0755)
if err != nil {
log.Fatal(err)
return err
}
return nil
})
return err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment