Skip to content

Commit

Permalink
fix: fix sync bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jonyhy96 committed Oct 17, 2019
1 parent c5f21bc commit b2be6c1
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/jonyhy96/replacer/pkg/replacer"
"github.com/jonyhy96/replacer/pkg/utils/file"
Expand All @@ -27,6 +28,7 @@ var (
defaultFileType = "json"
_replaceMap map[string]interface{}
err error
wg = sync.WaitGroup{}
rootCmd = &cobra.Command{
Use: "replacer",
Short: "replacer eplace things for you\n",
Expand All @@ -50,7 +52,9 @@ var (
if strings.Contains(replaceFilePath, info.Name()) {
return nil
}
wg.Add(1)
go func() {
defer wg.Done()
in, _ := os.Open(path) // omite error because of already under walk.
defer in.Close()
err = replacer.New(defaultFileType, _replaceMap, path).Replace(in)
Expand All @@ -60,6 +64,7 @@ var (
}()
return nil
})
wg.Wait()
log.Printf("Success replace all files under %s by %s!\n", workPath, replaceFilePath)
},
}
Expand Down

0 comments on commit b2be6c1

Please sign in to comment.