chore: minor cleanup

This commit is contained in:
andig 2023-02-27 16:15:03 +01:00
parent 78e5119855
commit c0d76a7918
3 changed files with 4 additions and 11 deletions

View file

@ -246,7 +246,7 @@ func pemBlockForKey(priv interface{}) (*pem.Block, error) {
func GetX509KeyPair(cert tls.Certificate) (string, string, error) {
var certValue, keyValue string
out := &bytes.Buffer{}
out := new(bytes.Buffer)
err := pem.Encode(out, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Certificate[0]})
if err == nil {
certValue = out.String()

View file

@ -4,7 +4,6 @@ import (
"bytes"
_ "embed"
"fmt"
"regexp"
"text/template"
"github.com/Masterminds/sprig/v3"
@ -16,7 +15,7 @@ var documentationTmpl string
//go:embed documentation_modbus.tpl
var documentationModbusTmpl string
// RenderProxy renders the proxy template
// RenderDocumentation renders the documentation template
func (t *Template) RenderDocumentation(product Product, values map[string]interface{}, lang string) ([]byte, error) {
for index, p := range t.Params {
for k, v := range values {
@ -100,11 +99,5 @@ func (t *Template) RenderDocumentation(product Product, values map[string]interf
err = tmpl.Execute(out, data)
}
// trim empty lines with whitespace
regex, _ := regexp.Compile("\n *\n")
string := regex.ReplaceAllString(out.String(), "\n\n")
result := new(bytes.Buffer)
result.WriteString(string)
return result.Bytes(), err
return []byte(trimEmptyLines(out.String())), err
}

View file

@ -205,7 +205,7 @@ func (t *Template) ModbusChoices() []string {
//go:embed proxy.tpl
var proxyTmpl string
// RenderProxy renders the proxy template
// RenderProxyWithValues renders the proxy template
func (t *Template) RenderProxyWithValues(values map[string]interface{}, lang string) ([]byte, error) {
tmpl, err := template.New("yaml").Funcs(template.FuncMap(sprig.FuncMap())).Parse(proxyTmpl)
if err != nil {