Skip to content

Commit

Permalink
Merge pull request #1 from nmnellis/logging
Browse files Browse the repository at this point in the history
logging and errors
  • Loading branch information
nmnellis authored Jul 6, 2021
2 parents 35b72af + 4577174 commit d2bb7aa
Showing 1 changed file with 23 additions and 25 deletions.
48 changes: 23 additions & 25 deletions pkg/generate/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@ func (a *AppGenerator) Generate() error {
return microservices[i].Name < microservices[j].Name
})

a.render(groupMicroservicesByNamespace(microservices))
return nil
return a.render(groupMicroservicesByNamespace(microservices))
}

func groupMicroservicesByNamespace(microservices []*Microservice) map[string][]*Microservice {
Expand All @@ -117,7 +116,7 @@ func groupMicroservicesByNamespace(microservices []*Microservice) map[string][]*
return namespaces
}

func (a *AppGenerator) render(microservices map[string][]*Microservice) {
func (a *AppGenerator) render(microservices map[string][]*Microservice) error {

testTemplate, err := template.New("template").Funcs(template.FuncMap{
"genUpstream": func(backends []*Backend) string {
Expand All @@ -134,13 +133,13 @@ func (a *AppGenerator) render(microservices map[string][]*Microservice) {
}).ParseGlob("pkg/generate/assets/*")
if err != nil {
log.Println(" template: ", err)
return
return err
}
if _, err := os.Stat(a.config.OutputDir); os.IsNotExist(err) {
err := os.Mkdir(a.config.OutputDir, os.ModePerm)
if err != nil {
log.Printf("create folder %s/: %v\n", a.config.OutputDir, err)
return
return err
}
}

Expand All @@ -154,47 +153,46 @@ func (a *AppGenerator) render(microservices map[string][]*Microservice) {
gatewayFile, err := os.Create(a.config.OutputDir + "/gateway.yaml")
if err != nil {
log.Println("create file: ", err)
return
return err
}

if err != nil {
panic(err)
}
err = testTemplate.ExecuteTemplate(gatewayFile, "gateway.yaml.tmpl", templateConfig)
if err != nil {
panic(err)
if err := testTemplate.ExecuteTemplate(gatewayFile, "gateway.yaml.tmpl", templateConfig); err != nil {
return err
}
log.Println("Generated Gateway config at " + gatewayFile.Name())

virtualserviceFile, err := os.Create(a.config.OutputDir + "/virtualservice.yaml")
if err != nil {
log.Println("create file: ", err)
return
return err
}
err = testTemplate.ExecuteTemplate(virtualserviceFile, "virtualservice.yaml.tmpl", templateConfig)
if err != nil {
panic(err)
if err := testTemplate.ExecuteTemplate(virtualserviceFile, "virtualservice.yaml.tmpl", templateConfig); err != nil {
return err
}
log.Println("Generated VirtualService config at " + virtualserviceFile.Name())

appFile, err := os.Create(a.config.OutputDir + "/app.yaml")
if err != nil {
log.Println("create file: ", err)
return
return err
}
err = testTemplate.ExecuteTemplate(appFile, "app.yaml.tmpl", templateConfig)
if err != nil {
panic(err)
if err := testTemplate.ExecuteTemplate(appFile, "app.yaml.tmpl", templateConfig); err != nil {
return err
}
log.Println("Generated App config at " + appFile.Name())

serviceEntryFile, err := os.Create(a.config.OutputDir + "/serviceentry.yaml")
if err != nil {
log.Println("create file: ", err)
return
return err
}
err = testTemplate.ExecuteTemplate(serviceEntryFile, "serviceentry.yaml.tmpl", templateConfig)
if err != nil {
panic(err)

if err := testTemplate.ExecuteTemplate(serviceEntryFile, "serviceentry.yaml.tmpl", templateConfig); err != nil {
return err
}
// fmt.Println(string(bytes))
log.Println("Generated ServiceEntry config at " + serviceEntryFile.Name())

return nil
}

func flattenTiers(tiers map[int][]*Microservice) (microservices []*Microservice) {
Expand Down

0 comments on commit d2bb7aa

Please sign in to comment.