1
0
mirror of https://github.com/lxc/distrobuilder.git synced 2026-02-05 15:46:17 +01:00
Files
distrobuilder/generators/common.go
Thomas Hipp 7a817de40f Satisfy static analysis
Signed-off-by: Thomas Hipp <thomas.hipp@canonical.com>
2023-04-24 08:37:18 +02:00

42 lines
851 B
Go

package generators
import (
"github.com/sirupsen/logrus"
"github.com/lxc/distrobuilder/shared"
)
type common struct {
logger *logrus.Logger
cacheDir string
sourceDir string
defFile shared.DefinitionFile
}
func (g *common) init(logger *logrus.Logger, cacheDir string, sourceDir string, defFile shared.DefinitionFile, def shared.Definition) {
g.logger = logger
g.cacheDir = cacheDir
g.sourceDir = sourceDir
g.defFile = defFile
render := func(val string) string {
if !defFile.Pongo {
return val
}
out, err := shared.RenderTemplate(val, def)
if err != nil {
logger.WithField("err", err).Warn("Failed to render template")
return val
}
return out
}
if defFile.Pongo {
g.defFile.Content = render(g.defFile.Content)
g.defFile.Path = render(g.defFile.Path)
g.defFile.Source = render(g.defFile.Source)
}
}