Skip to content

Commit

Permalink
Need to pass pointers to waitgroup
Browse files Browse the repository at this point in the history
  • Loading branch information
bmonkman committed Oct 25, 2019
1 parent dbab471 commit 325bfbe
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 23 deletions.
4 changes: 2 additions & 2 deletions cmd/create.go
Expand Up @@ -28,8 +28,8 @@ func Create(projectName string, outDir string, t *templator.Templator) string {
}
var wg sync.WaitGroup

util.TemplateFileIfDoesNotExist(rootDir, "commit0.yml", t.Commit0, wg, projectName)
util.TemplateFileIfDoesNotExist(rootDir, ".gitignore", t.GitIgnore, wg, projectName)
util.TemplateFileIfDoesNotExist(rootDir, "commit0.yml", t.Commit0, &wg, projectName)
util.TemplateFileIfDoesNotExist(rootDir, ".gitignore", t.GitIgnore, &wg, projectName)

wg.Wait()
return rootDir
Expand Down
16 changes: 8 additions & 8 deletions cmd/generate.go
Expand Up @@ -52,20 +52,20 @@ var generateCmd = &cobra.Command{
var wg sync.WaitGroup
switch language {
case Go:
proto.Generate(t, cfg, wg)
golang.Generate(t, cfg, wg)
proto.Generate(t, cfg, &wg)
golang.Generate(t, cfg, &wg)

docker.GenerateGoAppDockerFile(t, cfg, wg)
docker.GenerateGoDockerCompose(t, cfg, wg)
docker.GenerateGoAppDockerFile(t, cfg, &wg)
docker.GenerateGoDockerCompose(t, cfg, &wg)
case React:
react.Generate(t, cfg, wg)
react.Generate(t, cfg, &wg)
}

util.TemplateFileIfDoesNotExist("", "README.md", t.Readme, wg, cfg)
util.TemplateFileIfDoesNotExist("", "README.md", t.Readme, &wg, cfg)

if cfg.Network.Http.Enabled {
http.GenerateHTTPGW(t, cfg, wg)
docker.GenerateGoHTTPGWDockerFile(t, cfg, wg)
http.GenerateHTTPGW(t, cfg, &wg)
docker.GenerateGoHTTPGWDockerFile(t, cfg, &wg)
}

wg.Wait()
Expand Down
6 changes: 3 additions & 3 deletions internal/generate/docker/generate.go
Expand Up @@ -8,14 +8,14 @@ import (
"github.com/commitdev/commit0/internal/util"
)

func GenerateGoAppDockerFile(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func GenerateGoAppDockerFile(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
util.TemplateFileIfDoesNotExist("docker/app", "Dockerfile", templator.Docker.ApplicationDocker, wg, config)
}

func GenerateGoHTTPGWDockerFile(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func GenerateGoHTTPGWDockerFile(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
util.TemplateFileIfDoesNotExist("docker/http", "Dockerfile", templator.Docker.HttpGatewayDocker, wg, config)
}

func GenerateGoDockerCompose(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func GenerateGoDockerCompose(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
util.TemplateFileIfDoesNotExist("", "docker-compose.yml", templator.Docker.DockerCompose, wg, config)
}
4 changes: 2 additions & 2 deletions internal/generate/golang/generate.go
Expand Up @@ -11,14 +11,14 @@ import (
"github.com/commitdev/commit0/internal/util"
)

func Generate(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func Generate(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
util.TemplateFileIfDoesNotExist("", "main.go", templator.Go.GoMain, wg, config)
util.TemplateFileIfDoesNotExist("", "go.mod", templator.Go.GoMod, wg, config)
util.TemplateFileIfDoesNotExist("server/health", "health.go", templator.Go.GoHealthServer, wg, config)
GenerateServers(templator, config, wg)
}

func GenerateServers(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func GenerateServers(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
serverDirPath := "server"
err := util.CreateDirIfDoesNotExist(serverDirPath)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion internal/generate/http/generate.go
Expand Up @@ -8,6 +8,6 @@ import (
"github.com/commitdev/commit0/internal/util"
)

func GenerateHTTPGW(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func GenerateHTTPGW(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
util.TemplateFileAndOverwrite("http", "main.go", templator.Go.GoHTTPGW, wg, config)
}
4 changes: 2 additions & 2 deletions internal/generate/proto/generate.go
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/commitdev/commit0/internal/util"
)

func Generate(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func Generate(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
idlPath := fmt.Sprintf("%s-idl", config.Name)
idlHealthPath := fmt.Sprintf("%s/proto/health", idlPath)

Expand All @@ -24,7 +24,7 @@ func Generate(templator *templator.Templator, config *config.Commit0Config, wg s
GenerateProtoServiceLibs(config)
}

func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.Commit0Config, wg sync.WaitGroup) {
func GenerateServiceProtobufFiles(templator *templator.Templator, cfg *config.Commit0Config, wg *sync.WaitGroup) {
protoPath := fmt.Sprintf("%s-idl/proto", cfg.Name)
for _, s := range cfg.Services {
serviceProtoDir := fmt.Sprintf("%s/%s", protoPath, s.Name)
Expand Down
2 changes: 1 addition & 1 deletion internal/generate/react/generate.go
Expand Up @@ -7,6 +7,6 @@ import (
"github.com/commitdev/commit0/internal/templator"
)

func Generate(templator *templator.Templator, config *config.Commit0Config, wg sync.WaitGroup) {
func Generate(templator *templator.Templator, config *config.Commit0Config, wg *sync.WaitGroup) {
templator.React.TemplateFiles(config, false, wg)
}
2 changes: 1 addition & 1 deletion internal/templator/templator.go
Expand Up @@ -97,7 +97,7 @@ type DirectoryTemplator struct {
Templates []*template.Template
}

func (d *DirectoryTemplator) TemplateFiles(config *config.Commit0Config, overwrite bool, wg sync.WaitGroup) {
func (d *DirectoryTemplator) TemplateFiles(config *config.Commit0Config, overwrite bool, wg *sync.WaitGroup) {
for _, template := range d.Templates {
d, f := filepath.Split(template.Name())
if strings.HasSuffix(f, ".tmpl") {
Expand Down
7 changes: 4 additions & 3 deletions internal/util/util.go
Expand Up @@ -22,7 +22,7 @@ var FuncMap = template.FuncMap{
"Title": strings.Title,
}

func createTemplatedFile(fullFilePath string, template *template.Template, wg sync.WaitGroup, data interface{}) {
func createTemplatedFile(fullFilePath string, template *template.Template, wg *sync.WaitGroup, data interface{}) {
f, err := os.Create(fullFilePath)
if err != nil {
log.Printf("Error creating file: %v", err)
Expand All @@ -33,11 +33,12 @@ func createTemplatedFile(fullFilePath string, template *template.Template, wg sy
if err != nil {
log.Printf("Error templating: %v", err)
}
log.Printf("Finished templating : %v", fullFilePath)
wg.Done()
}()
}

func TemplateFileAndOverwrite(fileDir string, fileName string, template *template.Template, wg sync.WaitGroup, data interface{}) {
func TemplateFileAndOverwrite(fileDir string, fileName string, template *template.Template, wg *sync.WaitGroup, data interface{}) {
fullFilePath := fmt.Sprintf("%v/%v", fileDir, fileName)
err := os.MkdirAll(fileDir, os.ModePerm)
if err != nil {
Expand All @@ -47,7 +48,7 @@ func TemplateFileAndOverwrite(fileDir string, fileName string, template *templat

}

func TemplateFileIfDoesNotExist(fileDir string, fileName string, template *template.Template, wg sync.WaitGroup, data interface{}) {
func TemplateFileIfDoesNotExist(fileDir string, fileName string, template *template.Template, wg *sync.WaitGroup, data interface{}) {
fullFilePath := path.Join(fileDir, fileName)

if _, err := os.Stat(fullFilePath); os.IsNotExist(err) {
Expand Down

0 comments on commit 325bfbe

Please sign in to comment.