Quick actions

cmd+k|ctrl+k

Navigation

Languages

Essential Go / Text and HTML templates

Snippet info

Language

Go

Visibility

public

Author

kkowalczyk

Created

2019-03-26T10:11:26Z

Updated

2019-03-26T10:11:26Z

package main

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

func main() {
	tmplStr := "Data: {{.}}\n"
	t := template.Must(template.New("simple").Parse(tmplStr))
	execWithData := func(data interface{}) {
		err := t.Execute(os.Stdout, data)
		if err != nil {
			log.Fatalf("t.Execute() failed with '%s'\n", err)
		}
	}

	execWithData(5)
	execWithData("foo")
	st := struct {
		Number int
		Str    string
	}{
		Number: 3,
		Str:    "hello",
	}
	execWithData(st)
}
INFO