-
Notifications
You must be signed in to change notification settings - Fork 0
/
ne.go
45 lines (36 loc) · 864 Bytes
/
ne.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
package txttmpl
import (
"bytes"
"text/template"
"github.com/devlights/gomy/output"
)
// Ne -- text/template の テンプレート仕様 における ne (not equal) のサンプルです.
//
// # REFERENCES
// - https://pkg.go.dev/text/template@latest
func Ne() error {
const (
t1 = `{{$v := 10}} {{- if ne $v 10 -}} helloworld {{end}}`
t2 = `{{$v := 10}} {{- if ne $v 11 -}} helloworld {{end}}`
t3 = `{{$v := 10}} {{- if (ne $v 10) -}} helloworld {{end}}`
)
for _, t := range []string{t1, t2, t3} {
var (
tmpl *template.Template
buf bytes.Buffer
err error
)
output.Stdoutl("[template]", t)
tmpl, err = template.New("Ne").Parse(t)
if err != nil {
return err
}
err = tmpl.Execute(&buf, nil)
if err != nil {
return err
}
output.Stdoutf("[tmpl]", "%q\n", buf.String())
output.StdoutHr()
}
return nil
}