- Added upstream objects

- Renamed host templates to nginx templates
- Generate upstream templates
- Better nginx error reporting when reloading
- Use tparse for golang test reporting
This commit is contained in:
Jamie Curnow
2023-01-04 15:36:56 +10:00
parent b3ae2f4dbb
commit 5e5f0de0e2
82 changed files with 2209 additions and 294 deletions

View File

@ -6,7 +6,9 @@ import (
"npm/internal/entity/certificate"
"npm/internal/entity/host"
"npm/internal/entity/upstream"
"npm/internal/logger"
"npm/internal/util"
"github.com/aymerick/raymond"
)
@ -17,10 +19,15 @@ type TemplateData struct {
DataDir string
Host host.Template
Certificate certificate.Template
Upstream upstream.Model
}
func generateHostConfig(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 {
@ -31,7 +38,7 @@ func writeTemplate(filename, template string, data TemplateData) error {
// Write it. This will also write an error comment if generation failed
// nolint: gosec
writeErr := writeConfigFile(filename, output)
writeErr := writeConfigFile(filename, util.CleanupWhitespace(output))
if err != nil {
return err
}