package embed import ( "embed" "io" "io/fs" "os" "path/filepath" ) var ( //go:embed templates/* Templates embed.FS Assets embed.FS //go:embed data/* Data embed.FS ) func CopyToWorkingDirectory(data embed.FS) error { currentDir, err := os.Getwd() if err != nil { return err } if err := fs.WalkDir(data, ".", func(path string, info fs.DirEntry, err error) error { if err != nil { return err } fullPath := path if info.IsDir() { dirPath := filepath.Join(currentDir, path) if err := os.MkdirAll(dirPath, 0755); err != nil { return err } } else { srcFile, err := data.Open(fullPath) if err != nil { return err } dstFile, err := os.Create(filepath.Join(currentDir, path)) if err != nil { return err } defer dstFile.Close() _, err = io.Copy(dstFile, srcFile) if err != nil { return err } } return nil }); err != nil { return err } return nil }