Skip to content

Commit

Permalink
use helpers to reduce verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
kd7lxl committed May 5, 2021
1 parent 6b59537 commit b5c014d
Showing 1 changed file with 15 additions and 65 deletions.
80 changes: 15 additions & 65 deletions atlas/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,22 @@ func (app Application) Update() error {
// initializeFiles generates each file for a new application
func (app Application) initializeFiles() error {
fileInitializers := []func(Application) error{
Application.generateDockerfile,
Application.generateDeployFile,
Application.generateReadme,
Application.generateGitignore,
Application.generateMakefileVars,
app.generateFiles(
"templates/docker/Dockerfile.gotmpl",
"templates/deploy/config.yaml.gotmpl",
"templates/README.md.gotmpl",
"templates/.gitignore.gotmpl",
"templates/Makefile.gotmpl",
"templates/Makefile.vars.gotmpl",
"templates/Jenkinsfile.gotmpl",
"templates/pkg/pb/service.proto.gotmpl",
"templates/cmd/server/main.go.gotmpl",
"templates/cmd/server/grpc.go.gotmpl",
"templates/cmd/server/config.go.gotmpl",
"templates/pkg/svc/zserver.go.gotmpl",
"templates/pkg/svc/zserver_test.go.gotmpl",
),
Application.generateMakefileCommon,
Application.generateMakefile,
Application.generateJenkinsfile,
Application.generateProto,
Application.generateServerMain,
Application.generateServerGrpc,
Application.generateConfig,
Application.generateService,
Application.generateServiceTest,
}
if app.WithGateway {
fileInitializers = append(fileInitializers, Application.generateServerSwagger)
Expand Down Expand Up @@ -190,74 +192,22 @@ func (app Application) generateFiles(tmplPaths ...string) func(Application) erro
}
}

func (app Application) generateDockerfile() error {
return app.generateFile("docker/Dockerfile", "templates/docker/Dockerfile.gotmpl")
}

func (app Application) generateDeployFile() error {
return app.generateFile("deploy/config.yaml", "templates/deploy/config.yaml.gotmpl")
}

func (app Application) generateMigrationFile() error {
return app.generateFile("deploy/migrations.yaml", "templates/deploy/migrations.yaml.gotmpl")
}

func (app Application) generateReadme() error {
return app.generateFile("README.md", "templates/README.md.gotmpl")
}

func (app Application) generateGitignore() error {
return app.generateFile(".gitignore", "templates/.gitignore.gotmpl")
}

func (app Application) generateMakefile() error {
return app.generateFile("Makefile", "templates/Makefile.gotmpl")
}

func (app Application) generateMakefileVars() error {
return app.generateFile("Makefile.vars", "templates/Makefile.vars.gotmpl")
}

func (app Application) generateMakefileCommon() error {
return app.generateFile("Makefile.common", "templates/Makefile.common.gotmpl")
}

func (app Application) generateJenkinsfile() error {
return app.generateFile("Jenkinsfile", "templates/Jenkinsfile.gotmpl")
}

func (app Application) generateProto() error {
return app.generateFile("pkg/pb/service.proto", "templates/pkg/pb/service.proto.gotmpl")
}

func (app Application) generateServerMain() error {
return app.generateFile("cmd/server/main.go", "templates/cmd/server/main.go.gotmpl")
}

func (app Application) generateServerProfiler() error {
return app.generateFile("cmd/server/profiler.go", "templates/cmd/server/profiler.go.gotmpl")
}

func (app Application) generateServerGrpc() error {
return app.generateFile("cmd/server/grpc.go", "templates/cmd/server/grpc.go.gotmpl")
}

func (app Application) generateServerSwagger() error {
return app.generateFile("cmd/server/swagger.go", "templates/cmd/server/swagger.go.gotmpl")
}

func (app Application) generateConfig() error {
return app.generateFile("cmd/server/config.go", "templates/cmd/server/config.go.gotmpl")
}

func (app Application) generateService() error {
return app.generateFile("pkg/svc/zserver.go", "templates/pkg/svc/zserver.go.gotmpl")
}

func (app Application) generateServiceTest() error {
return app.generateFile("pkg/svc/zserver_test.go", "templates/pkg/svc/zserver_test.go.gotmpl")
}

func (app Application) generateHelmCharts() error {
for helmPath, tmplPath := range app.Helm.GetFiles(app.WithDatabase) {
if err := app.generateFile(helmPath, tmplPath); err != nil {
Expand Down

0 comments on commit b5c014d

Please sign in to comment.