Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save pinzolo/74697097dc4ecd0373e55caeb24a3992 to your computer and use it in GitHub Desktop.
Save pinzolo/74697097dc4ecd0373e55caeb24a3992 to your computer and use it in GitHub Desktop.
package main
import (
"os"
"text/template"
)
type Person struct {
Name string
City string
}
func (p Person) GetAge() int {
return 36
}
func main() {
tmpl, err := template.New("test").Parse("{{.Name}}({{.GetAge}}) lives in {{.City}}.")
if err != nil {
panic(err)
}
p := Person{"pinzolo", "Kyoto"}
err = tmpl.Execute(os.Stdout, p)
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment