Skip to content

Instantly share code, notes, and snippets.

@pinzolo
Last active June 3, 2016 01:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinzolo/983a9e69eed21278de6ee03ec09a45b0 to your computer and use it in GitHub Desktop.
Save pinzolo/983a9e69eed21278de6ee03ec09a45b0 to your computer and use it in GitHub Desktop.
text/template から カッコつきでメソッドを呼び出してみる(出来ない)
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