Created
February 19, 2017 09:04
-
-
Save DavadDi/229f554f6a4a86e40df5e19f077b0f51 to your computer and use it in GitHub Desktop.
html_template.go
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 ( | |
"html/template" | |
"os" | |
) | |
type Class struct { | |
Name string | |
Value int32 | |
} | |
type EntetiesClass struct { | |
Name string | |
Cls Class | |
} | |
// In the template, we use rangeStruct to turn our struct values | |
// into a slice we can iterate over | |
const htmlTemplate = ` | |
{{range .}} | |
{{.Name}} {{.Cls.Name}} {{.Cls.Value}} | |
{{end}} | |
` | |
func main() { | |
data := []EntetiesClass{ | |
{"Yoga1", Class{"CLA1", 12}}, {"Yoga2", Class{"CLA2", 15}}, | |
} | |
t := template.New("t") | |
t, err := t.Parse(htmlTemplate) | |
if err != nil { | |
panic(err) | |
} | |
err = t.Execute(os.Stdout, data) | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment