Example #1
0
File: main.go Project: nyodas/cnt
func Run(overrideEnvVarName string, target string, templaterDir string, continueOnError bool) {
	attrMerger, err := merger.NewAttributesMerger(templaterDir + pathAttributes)
	if err != nil {
		logs.WithE(err).Warn("Failed to prepare attributes")
	}
	attributes := attrMerger.Merge()
	attributes = overrideWithJsonIfNeeded(overrideEnvVarName, attributes)
	tt, err := merger.ProcessAttributesTemplating(attributes, attributes)
	attributes = tt.(map[string]interface{})
	if err != nil {
		logs.WithField("dir", templaterDir+pathTemplates).Fatal("Failed to template attributes")
	}
	logs.WithField("content", attributes).Debug("Final attributes resolution")

	info, _ := os.Stat(templaterDir + pathTemplates)
	if info == nil {
		logs.WithField("dir", templaterDir+pathTemplates).Debug("Template dir is empty. Nothing to template")
		return
	}
	tmpl, err := template.NewTemplateDir(templaterDir+pathTemplates, target, continueOnError)
	if err != nil {
		logs.WithE(err).WithField("dir", templaterDir+pathTemplates).Fatal("Failed to load template dir")
	}
	err = tmpl.Process(attributes)
	if err != nil {
		logs.WithE(err).WithField("dir", templaterDir+pathTemplates).Fatal("Failed to process template dir")
	}
}
Example #2
0
File: env.go Project: blablacar/ggn
func (e *Env) loadPartials() {
	if ok, err := common.IsDirEmpty(e.path + PATH_TEMPLATES); ok || err != nil {
		return
	}
	tmplDir, err := template.NewTemplateDir(e.path+PATH_TEMPLATES, "", false)
	if err != nil {
		logs.WithEF(err, e.fields).WithField("path", e.path+PATH_ATTRIBUTES).Fatal("Failed to load partial templating")
	}
	e.Partials = tmplDir.Partials
}