Created
October 31, 2011 19:15
-
-
Save gregworley/1328550 to your computer and use it in GitHub Desktop.
golang r60 template package example using range on a slice of maps and accessing keys
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 ( | |
"template" | |
"os" | |
) | |
const levelsT = `levels: [ | |
{{range $h := .}} {{"{"}}bitrate:{{$h.bitrate}}, file:"{{$h.file}}", width:{{$h.width}}, height:{{$h.height}}{{"}"}} | |
{{end}}] | |
` | |
func main() { | |
file1 := map[string]string{"bitrate": "896", "file": "small.mp4", "width": "480", "height": "272"} | |
file2 := map[string]string{"bitrate": "1000", "file": "medium.mp4", "width": "1280", "height": "720"} | |
file3 := map[string]string{"bitrate": "2128", "file": "large.mp4", "width":"1920", "height": "1080"} | |
levels := []map[string]string{file1, file2, file3} | |
t1 := template.Must(template.New("levels").Parse(levelsT)) | |
t1.Execute(os.Stdout, levels) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment