Use upstream in host config

This commit is contained in:
Jamie Curnow
2023-01-06 11:42:02 +10:00
parent bc6825c148
commit 17a108f75f
6 changed files with 49 additions and 25 deletions

View File

@ -13,25 +13,29 @@ import (
"github.com/aymerick/raymond"
)
type Config struct {
Ipv4 bool
Ipv6 bool
}
// TemplateData is a struct
type TemplateData struct {
ConfDir string
Config Config
DataDir string
Host host.Template
Certificate certificate.Template
Upstream upstream.Model
}
func generateHostConfig(template string, data TemplateData) (string, error) {
func renderTemplate(template string, data TemplateData) (string, error) {
logger.Debug("Rendering Template - Template: %s", template)
logger.Debug("Rendering Template - Data: %+v", data)
return raymond.Render(template, data)
// todo: apply some post processing to this config, stripe trailing whitespace from lines and then remove groups of 2+ \n's so the config looks nicer
}
func writeTemplate(filename, template string, data TemplateData) error {
output, err := generateHostConfig(template, data)
output, err := renderTemplate(template, data)
if err != nil {
output = fmt.Sprintf("# Template Error: %s", err.Error())
}