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 Jan 10, 2024
1 parent fc1832c commit d32ef78
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 @@ -72,21 +72,23 @@ 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,
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.generateGoMod,
Application.generateGitignore,
Application.generateMakefileVars,
Application.generateMakefileCommon,
Application.generateMakefile,
Application.generateJenkinsfile,
Application.generateProto,
Application.generateServerMain,
Application.generateServerGrpc,
Application.generateConfig,
Application.generateService,
Application.generateServiceTest,
}
if app.WithSubscribeTopic != "" || app.WithPublishTopic != "" {
fileInitializers = append(fileInitializers, Application.generatePubsub, Application.generatePubsubTest)
Expand Down Expand Up @@ -234,38 +236,18 @@ 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) generateDockerfileDebug() error {
return app.generateFile("docker/Dockerfile.debug", "templates/docker/Dockerfile.debug.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) generateGoMod() error {
return app.generateFile("go.mod", "templates/go.mod.gotmpl")
}

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

func (app Application) generateMakefileKind() error {
return app.generateFile("Makefile.kind", "templates/Makefile.kind.gotmpl")
}
Expand All @@ -274,42 +256,18 @@ func (app Application) generateMakefileDebugger() error {
return app.generateFile("Makefile.remotedebug", "templates/Makefile.remotedebug.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) generatePubsub() error {
return app.generateFile("pkg/dapr/pubsub.go", "templates/pkg/dapr/pubsub.go.gotmpl")
}
Expand All @@ -318,14 +276,6 @@ func (app Application) generatePubsubTest() error {
return app.generateFile("pkg/dapr/pubsub_test.go", "templates/pkg/dapr/pubsub_test.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 d32ef78

Please sign in to comment.