add chapter 15.7 (#683)

This commit is contained in:
marjune
2019-07-16 10:55:54 +08:00
committed by ᴊ. ᴄʜᴇɴ
parent 9580580bda
commit c78236269d
8 changed files with 438 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
// template_field.go
package main
import (
"fmt"
"os"
"text/template"
)
type Person struct {
Name string
nonExportedAgeField string
}
func main() {
t := template.New("hello")
t, _ = t.Parse("hello {{.Name}}!")
p := Person{Name: "Mary", nonExportedAgeField: "31"}
if err := t.Execute(os.Stdout, p); err != nil {
fmt.Println("There was an error:", err.Error())
}
}
// Output: hello Mary!