Quick actions

cmd+k|ctrl+k

Navigation

Languages

Text and HTML templates / Built-in functions / Essential Go

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:16:44Z

Updated

2019-03-26T10:16:44Z

package main

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

const tmplStr = `print:   {{ print .Str .Num }}
println: {{ println .Str .Num }}
printf:  {{ printf "%s %#v %d" .Str .Str .Num }}
`

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

	data := struct {
		Str string
		Num int
	}{
		Str: "str",
		Num: 8,
	}
	err := t.Execute(os.Stdout, data)
	if err != nil {
		log.Fatalf("t.Execute() failed with '%s'\n", err)
	}
}
INFO