Created
March 13, 2017 13:02
-
-
Save shouhei/da8b6238383993a4c17665cc28e68e13 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"os" | |
"text/template" | |
) | |
type Hoge struct { | |
Count int | |
Material string | |
} | |
type T struct { | |
Data []Hoge | |
} | |
func main() { | |
sweaters := []Hoge{Hoge{1, "hogehuga"}, Hoge{2, "hugahuga"}, Hoge{3, "piyopiyo"}} | |
tmpl, err := template.New("test").Parse(`{{range $_, $hoge := .Data}}{{$hoge.Count}} items are made of {{$hoge.Material}} | |
{{end}}`) | |
if err != nil { | |
panic(err) | |
} | |
err = tmpl.Execute(os.Stdout, T{sweaters}) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment