I am new to Go. I have been searching Documentation. In the following playground code, it is rendering and printing it on the screen. I want the rendered text to be stored in string so that I can return it from a function.
package main
import (
"os"
"text/template"
)
type Person struct {
Name string //exported field since it begins with a capital letter
}
func main() {
t := template.New("sammple") //create a new template with some name
t, _ = t.Parse("hello {{.Name}}!") //parse some content and generate a template, which is an internal representation
p := Person{Name:"Mary"} //define an instance with required field
t.Execute(os.Stdout, p) //merge template âtâ with content of âpâ
}
https://play.golang.org/p/-qIGNSfJwEX
How to do it ?