github.com/verrazzano/verrazzano@v1.7.1/tools/vz/pkg/templates/templates.go (about)

     1  // Copyright (c) 2022, 2023, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package templates
     5  
     6  import (
     7  	"bytes"
     8  	"text/template"
     9  )
    10  
    11  // ApplyTemplate - apply the replacement parameters to the specified template content
    12  func ApplyTemplate(templateContent string, params interface{}) (string, error) {
    13  
    14  	// Parse the template file
    15  	testTemplate, err := template.New("cli").Parse(templateContent)
    16  	if err != nil {
    17  		return "", err
    18  	}
    19  
    20  	// Apply the replacement parameters to the template
    21  	var buf bytes.Buffer
    22  	err = testTemplate.Execute(&buf, &params)
    23  	if err != nil {
    24  		return "", err
    25  	}
    26  
    27  	// Return the result
    28  	return buf.String(), nil
    29  }