-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconst.go
More file actions
37 lines (32 loc) · 817 Bytes
/
const.go
File metadata and controls
37 lines (32 loc) · 817 Bytes
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
package gg
import "io"
type iconst struct {
items *Group
}
func Const() *iconst {
i := &iconst{
items: newGroup("(", ")", "\n"),
}
i.items.omitWrapIf = func() bool {
// We only need to omit wrap while length == 1.
// NewIf length == 0, we need to keep it, or it will be invalid expr.
return i.items.length() == 1
}
return i
}
func (i *iconst) render(w io.Writer) {
writeString(w, "const ")
i.items.render(w)
}
func (i *iconst) AddField(name, value interface{}) *iconst {
i.items.append(field(name, value, "="))
return i
}
func (i *iconst) AddTypedField(name, typ, value interface{}) *iconst {
i.items.append(typedField(name, typ, value, "="))
return i
}
func (i *iconst) AddLineComment(content string, args ...interface{}) *iconst {
i.items.append(LineComment(content, args...))
return i
}