-
Notifications
You must be signed in to change notification settings - Fork 0
/
and.go
46 lines (37 loc) · 880 Bytes
/
and.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package txttmpl
import (
"bytes"
"text/template"
"github.com/devlights/gomy/output"
)
// And -- text/template の テンプレート仕様 における and のサンプルです.
//
// # REFERENCES
// - https://pkg.go.dev/text/template@latest
func And() error {
var (
tmpls = []string{
`{{ if and (eq .Hello "hello") (eq .World "world") }} hello world {{end}}`,
`{{ if and (eq .Hello "world") (eq .World "hello") }} hello world {{end}}`,
}
)
for _, t := range tmpls {
var (
tmpl *template.Template
buf bytes.Buffer
err error
)
output.Stdoutl("[template]", t)
tmpl, err = template.New("And").Parse(t)
if err != nil {
return err
}
err = tmpl.Execute(&buf, struct{ Hello, World string }{"hello", "world"})
if err != nil {
return err
}
output.Stdoutf("[tmpl]", "%q\n", buf.String())
output.StdoutHr()
}
return nil
}