Quick actions

cmd+k|ctrl+k

Navigation

Languages

Text and HTML templates / range action / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:16:33Z

Updated

2019-03-26T10:16:33Z

package main

import (
	"log"
	"os"
	"text/template"
)

const tmplStr = `Elements of map:
{{ range $k, $v := . }}{{ $k }}: {{ $v }}
{{end}}`

func main() {
	t := template.Must(template.New("range").Parse(tmplStr))

	data := map[string]int{
		"one":  1,
		"five": 5,
	}
	err := t.Execute(os.Stdout, data)
	if err != nil {
		log.Fatalf("t.Execute() failed with '%s'\n", err)
	}
}
INFO