package tmpl import ( "bytes" "io" ) type Executor interface { Execute(wr io.Writer, data interface{}) error } // AsString to convert template to string func AsString(t Executor, data interface{}) (string, error) { var buf bytes.Buffer if err := t.Execute(&buf, data); err != nil { return "", err } return buf.String(), nil } // String to convert template to string and ignores errors func String(t Executor, data interface{}) string { if result, err := AsString(t, data); err == nil { return result } else { return "" } }