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:40Z

Updated

2019-03-26T10:16:40Z

package main

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

type Data struct {
	True  bool
	False bool
}

const tmplStr = `Or:  {{ if or .True .False }}true{{ else }}false{{ end }}
And: {{ if and .True .False }}true{{ else }}false{{ end }}
Not: {{ if not .False }}true{{ else }}false{{ end }}
`

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

	data := Data{True: true, False: false}

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