mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
47 lines
1.0 KiB
Go
47 lines
1.0 KiB
Go
package nginx
|
|
|
|
import (
|
|
"fmt"
|
|
"io/ioutil"
|
|
|
|
"npm/internal/entity/certificate"
|
|
"npm/internal/entity/host"
|
|
"npm/internal/logger"
|
|
|
|
"github.com/aymerick/raymond"
|
|
)
|
|
|
|
// TemplateData ...
|
|
type TemplateData struct {
|
|
ConfDir string
|
|
DataDir string
|
|
CertsDir string
|
|
Host *host.Model
|
|
Certificate *certificate.Model
|
|
}
|
|
|
|
func generateHostConfig(template string, data TemplateData) (string, error) {
|
|
return raymond.Render(template, data)
|
|
}
|
|
|
|
func writeTemplate(filename, template string, data TemplateData) error {
|
|
output, err := generateHostConfig(template, data)
|
|
if err != nil {
|
|
output = fmt.Sprintf("# Template Error: %s", err.Error())
|
|
}
|
|
|
|
// Write it. This will also write an error comment if generation failed
|
|
// nolint: gosec
|
|
writeErr := writeConfigFile(filename, output)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
return writeErr
|
|
}
|
|
|
|
func writeConfigFile(filename, content string) error {
|
|
logger.Debug("Writing %s with:\n%s", filename, content)
|
|
// nolint: gosec
|
|
return ioutil.WriteFile(filename, []byte(content), 0644)
|
|
}
|