github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/internal/tprint.go (about)

     1  package internal
     2  
     3  import (
     4  	"bytes"
     5  	"text/template"
     6  )
     7  
     8  // Tprintf renders a string from a given template string and field values
     9  func Tprintf(tmpl string, data map[string]interface{}) string {
    10  	t := template.Must(template.New("").Parse(tmpl))
    11  	buf := &bytes.Buffer{}
    12  	if err := t.Execute(buf, data); err != nil {
    13  		return ""
    14  	}
    15  	return buf.String()
    16  }