github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2015/tricks/template.go (about) 1 // +build ignore 2 3 package main 4 5 import ( 6 "log" 7 "os" 8 "strings" 9 "text/template" 10 ) 11 12 func main() { 13 tmpl := template.Must(template.New("").Parse(strings.TrimSpace(` 14 Dear {{.Title}} {{.Lastname}}, 15 16 Congratulations on reaching Level {{.Rank}}! 17 I'm sure your parents would say "Great job, {{.Firstname}}!" 18 19 Sincerely, 20 Rear Admiral Gopher 21 `))) 22 // BEGIN OMIT 23 data := struct { 24 Title string 25 Firstname, Lastname string 26 Rank int 27 }{ 28 "Dr", "Carl", "Sagan", 7, 29 } 30 if err := tmpl.Execute(os.Stdout, data); err != nil { 31 log.Fatal(err) 32 } 33 // END OMIT 34 }