Created
November 15, 2022 02:19
-
-
Save CrimsonK1ng/3f42f05c2586fabf83382dd1ba3ecf0e to your computer and use it in GitHub Desktop.
Copy Embed FS To Disk
This file contains 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
//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